[Insight-developers] Fwd: [Insight-users] DicomSeriesReaderSeriesWriter.cxx doesnot write Image position Patient and image orientation patient Z values
frankmiller at jhmi.edu
frankmiller at jhmi.edu
Mon Jun 9 11:56:20 EDT 2008
Mathieu,
When I reproduce the problem you reported, I get the following.
Original Positions:
Image Position (Patient) = -112\ -21.688\ 126.894
Image Position (Patient) = -112\-20.2729\ 127.641
Image Position (Patient) = -112\-18.8578\ 128.388
Output Positions:
Image Position (Patient) = -112.000000\-21.688000\126.893997
Image Position (Patient) = -112.000000\-21.688000\128.494160
Image Position (Patient) = -112.000000\-21.688000\130.094322
The reason this is happening is caused by
itk::Image::TransformIndexToPhysicalPoint().
which assumes the image direction is the identity. Thus the value
calculated for origin2 is wrong. If itk::OrientedImage is used instead,
I get the expected positions.
Frank
On Mon, Jun 09, 2008 at 04:30:06PM +0200, Mathieu Malaterre wrote:
> while working on a issue (from itk-users list), I realized there is
> still some issue with the trick with 'ITK_Origin' in Series writer.
> The following code:
>
>
> cat itkImageSeriesWriter.txx
> ...
> if( m_ImageIO )
> {
> DictionaryType & dictionary = m_ImageIO->GetMetaDataDictionary();
>
>
> typename InputImageType::SpacingType spacing2 =
> inputImage->GetSpacing();
>
> // origin of the output slice in the
> // N-Dimensional space of the input image.
> typename InputImageType::PointType origin2;
>
> inputImage->TransformIndexToPhysicalPoint( inIndex, origin2 );
>
> const unsigned int inputImageDimension = TInputImage::ImageDimension;
>
> typedef Array< double > DoubleArrayType;
>
> DoubleArrayType originArray( inputImageDimension );
> DoubleArrayType spacingArray( inputImageDimension );
>
> for( unsigned int d = 0; d < inputImageDimension; d++ )
> {
> originArray[ d ] = origin2[ d ];
> spacingArray[ d ] = spacing2[ d ];
> }
>
> EncapsulateMetaData< DoubleArrayType >( dictionary,
> ITK_Origin, originArray );
> EncapsulateMetaData< DoubleArrayType >( dictionary,
> ITK_Spacing, spacingArray );
> EncapsulateMetaData< unsigned int >( dictionary,
> ITK_NumberOfDimensions, inputImageDimension );
>
> }
> ...
>
> does not produce the expected Image Position (Patient).
>
> Steps to reproduce, you simply need to run the
> DicomSeriesReadSeriesWrite.cxx example. You need to comment out the
> lines:
>
> // seriesWriter->SetMetaDataDictionaryArray(
> // reader->GetMetaDataDictionaryArray() );
>
>
> then run like this:
>
> $ make DicomSeriesReadSeriesWrite && ./bin/DicomSeriesReadSeriesWrite
> ../Insight/Testing/Data/Input/DicomSeries bla
>
> It will produce the following Image Position (Patient):
>
> $ dcmdump ../Insight/Testing/Data/Input/DicomSeries/Image00*.dcm | grep ImagePos
> (0020,0032) DS [-112\ -21.688\ 126.894] # 22, 3
> ImagePositionPatient
> (0020,0032) DS [-112\-20.2729\ 127.641] # 22, 3
> ImagePositionPatient
> (0020,0032) DS [-112\-18.8578\ 128.388] # 22, 3
> ImagePositionPatient
>
> $ dcmdump bla/Image007* | grep ImagePos
> (0020,0032) DS [-112\-18.8578\ 128.388] # 22, 3
> ImagePositionPatient
> (0020,0032) DS [-112\-18.8578\ 128.388] # 22, 3
> ImagePositionPatient
> (0020,0032) DS [-112\-18.8578\ 128.388] # 22, 3
> ImagePositionPatient
>
> Indeed the Spacing Beween Slices is correct (1.6) but the direction is
> not respected.
>
> Is this the intended behavior, does the user has to explicitely make
> use of an itk::OrientedImage for this to work ?
>
> Thanks
> -Mathieu
>
>
> ---------- Forwarded message ----------
> From: Mathieu Malaterre <mathieu.malaterre at gmail.com>
> Date: Mon, Jun 9, 2008 at 4:22 PM
> Subject: Re: [Insight-users] DicomSeriesReaderSeriesWriter.cxx doesnot
> write Image position Patient and image orientation patient Z values
> To: Sachin Jambawalikar <sachinjam at gmail.com>
> Cc: insight-users at itk.org
>
>
> On Sun, Jun 8, 2008 at 3:17 AM, Sachin Jambawalikar <sachinjam at gmail.com> wrote:
> > Hi all,
> >
> > I was trying to use the DicomSeriesWriter.cxx examples in the
> > Examples/IO directory to just read a dicom series and write it to a
> > new directory.
> > The series writer produces the dicom files fine but when you see the
> > dicom header the
> > tags are wrong for example
> >
> > the original file tag values are :
> >
> > 0020,0032,Image Position Patient=
> > -102.34347617253\-156.03754969686\-62.252762846648
> > 0020,0037,Image Orientation (Patient)=
> > 0.99587732553482\0.07696951180696\0.04800064116716\-0.0597707442939\0.95484501123428\-0.2910300195217
> >
> > and the tags for the generated dcm file is:
> > 0020,0032,Image Position Patient= -102.343475\-156.037552\0.000000
> > 0020,0037,Image Orientation (Patient)=
> > 0.995877\-0.059771\0.000000\0.076970\0.954845\0.000000
> >
> > I guess the problem is in the itk:ImageSeriesWriter() which assumes
> > the output datatype to be 2D and hence wihle writing the metadata info
> > trunctates it only for the image dimension
> > I''ve used the
> > inputdict=reader->GetMetaDataDictionaryArray() ;
> > std::string imagepositionpatient;
> > itk::ExposeMetaData<std::string>(*inputDict, "0020|0032",
> > imagepositionpatient) and it reads the right values.
> >
> > I want to use this to read a dicom series process the dicom series
> > and save this processed data as a new series in the study.
> > The wrong IPP and IOP tags causes problems when viewing this
> > generated series in any pacs viewer when the study is loaded.
> >
> > Is there a way around this or am I doing something wrong ??()
> >
> > Thanks
> >
> > Regards
> > Sachin Jambawalikar
> > _______________________________________________
> > Insight-users mailing list
> > Insight-users at itk.org
> > http://www.itk.org/mailman/listinfo/insight-users
> >
>
> Sachin,
>
> I have just patch ITK:
> $ cvs ci -m"ENH: When used explicitely makes use of the
> SetMetaDataDictionaryArray/GetMetaDataDictionaryArray we should use
> information from the meta data dict. I did not handle the spacing,
> since spacing in DICOM is also 2D thus it SHOULD match whatever
> information was in the dict. Only Orienation and Position are 3D in a
> 2D image, which is difficult to handle in ITK"
> /cvsroot/Insight/Insight/Code/IO/itkGDCMImageIO.cxx,v <-- itkGDCMImageIO.cxx
> new revision: 1.143; previous revision: 1.142
>
> If you could try that ASAP, I believe this fix the issue you are seeing.
>
> Steps:
>
> $ make DicomSeriesReadSeriesWrite && ./bin/DicomSeriesReadSeriesWrite
> ../Insight/Testing/Data/Input/DicomSeries bla
>
> $ dcmdump ../Insight/Testing/Data/Input/DicomSeries/Image00*.dcm | grep ImageOr
> (0020,0037) DS [ 1\ 0\ 0\ 0\0.466651\ -0.884442] # 32, 6
> ImageOrientationPatient
> (0020,0037) DS [ 1\ 0\ 0\ 0\0.466651\ -0.884442] # 32, 6
> ImageOrientationPatient
> (0020,0037) DS [ 1\ 0\ 0\ 0\0.466651\ -0.884442] # 32, 6
> ImageOrientationPatient
>
> $ dcmdump bla/Image007* | grep ImageOri
> (0020,0037) DS [ 1\ 0\ 0\ 0\0.466651\ -0.884442] # 32, 6
> ImageOrientationPatient
> (0020,0037) DS [ 1\ 0\ 0\ 0\0.466651\ -0.884442] # 32, 6
> ImageOrientationPatient
> (0020,0037) DS [ 1\ 0\ 0\ 0\0.466651\ -0.884442] # 32, 6
> ImageOrientationPatient
>
>
> And same for Position:
>
> $ dcmdump bla/Image007* | grep ImagePos
> (0020,0032) DS [-112\ -21.688\ 126.894] # 22, 3
> ImagePositionPatient
> (0020,0032) DS [-112\-20.2729\ 127.641] # 22, 3
> ImagePositionPatient
> (0020,0032) DS [-112\-18.8578\ 128.388] # 22, 3
> ImagePositionPatient
>
> $ dcmdump ../Insight/Testing/Data/Input/DicomSeries/Image00*.dcm | grep ImagePos
> (0020,0032) DS [-112\ -21.688\ 126.894] # 22, 3
> ImagePositionPatient
> (0020,0032) DS [-112\-20.2729\ 127.641] # 22, 3
> ImagePositionPatient
> (0020,0032) DS [-112\-18.8578\ 128.388] # 22, 3
> ImagePositionPatient
>
>
> Please note, that you *HAVE TO* use the
> SetMetaDataDictionaryArray/GetMetaDataDictionaryArray API for this to
> works.
>
> Thanks,
> --
> Mathieu
>
>
>
> --
> Mathieu
> _______________________________________________
> Insight-developers mailing list
> Insight-developers at itk.org
> http://www.itk.org/mailman/listinfo/insight-developers
More information about the Insight-developers
mailing list