[Insight-users] problem with orientation of dicom output from segmentation

John Drozd john.drozd at gmail.com
Thu Nov 26 15:22:03 EST 2009


Hi Luis,

I was getting a segmentation fault because I had forgotten to change the
Dimension from 2 to 3 in DicomReadPrintTag.cxx.

For the input image, I have:
(0020|0037) Image Orientation (Patient) = 0.0\0.0\-1.0\0.0\1.0\0.0

For the output image, I have:
(0020|0037) Image Orientation (Patient) =
0.000000\0.000000\1.000000\0.000000\1.000000\0.000000

There is a difference.  Since the program is changing the orientation when
processed through the pipeline, is the best approach to manually change the
orientation tag of the dictionary and then copy the revised dictionary to
the output file?

john

Below are the full tags:

[jdrozd at trumpet DicomImageReadPrintTags]$ ./DicomImageReadPrintTags
correctedsubject5.dcm
(0002|0000) Group Length =
214
(0002|0001) File Meta Information Version =
AAE=
(0002|0002) Media Storage SOP Class UID =
1.2.840.10008.5.1.4.1.1.2
(0002|0003) Media Storage SOP Instance UID =
1.2.826.0.1.3680043.2.1125.1.10607669833050788267094246636093811
(0002|0010) Transfer Syntax UID =
1.2.840.10008.1.2.1
(0002|0012) Implementation Class UID =
147.144.143.155
(0002|0013) Implementation Version Name = ITK/GDCM
1.2.4
(0002|0016) Source Application Entity Title =
NOTSPECIFIED
(0008|0008) Image Type =
DERIVED\PRIMARY

(0008|0012) Instance Creation Date =
20091029
(0008|0013) Instance Creation Time =
135224
(0008|0016) SOP Class UID =
1.2.840.10008.5.1.4.1.1.2

(0008|0018) SOP Instance UID =
1.2.826.0.1.3680043.2.1125.1.10607669833050788267094246636093811

(0008|0020) Study Date =
20081030

(0008|0030) Study Time =
164348.940

(0008|0050) Accession Number
=

(0008|0060) Modality =
CT

(0008|0064) Conversion Type =
WSD

(0008|0070) Manufacturer =
Manifacturer

(0008|0080) Institution Name = GDCM
Hospital
(0008|0090) Referring Physician's Name = Refering
Phisician
(0010|0010) Patient's Name = Patient
188858520
(0010|0020) Patient ID =
1747233212

(0010|0030) Patient's Birth Date =
19500101
(0010|0040) Patient's Sex =
M

(0018|0088) Spacing Between Slices =
1.207500
(0018|1164) Imager Pixel Spacing =
0.945750\0.945750
(0020|000d) Study Instance UID =
1.2.826.0.1.3680043.2.1125.1.53653479342656887425609263146205769
(0020|000e) Series Instance UID =
1.2.826.0.1.3680043.2.1125.1.47155241092896696198844159625679986
(0020|0010) Study ID =
1533117581

(0020|0011) Series Number =
2135500125

(0020|0013) Instance Number =
165

(0020|0020) Patient Orientation =
L\P
(0020|0032) Image Position (Patient) =
199.237496852874\0.0\0.0
(0020|0037) Image Orientation (Patient) =
0.0\0.0\-1.0\0.0\1.0\0.0
(0020|4000) Image Comments = NOT FOR CLINICAL
USE
(0028|0002) Samples per Pixel =
1

(0028|0004) Photometric Interpretation =
MONOCHROME2
(0028|0008) Number of Frames =
166

(0028|0010) Rows =
256

(0028|0011) Columns =
256

(0028|0030) Pixel Spacing =
0.945750\0.945750

(0028|0034) Pixel Aspect Ratio =
1\1
(0028|0100) Bits Allocated =
16

(0028|0101) Bits Stored =
16

(0028|0102) High Bit =
15

(0028|0103) Pixel Representation =
0
(0028|1052) Rescale Intercept =
0.0

(0028|1053) Rescale Slope =
1.0

(0028|1054) Rescale Type =
US

(7fe0|0000) Group Length =
21757964

Patient's Name (0010|0010)  is: Patient
188858520
Performing Physician's Name (0008|1050): (No Value Found in
File)
PixelType:
scalar

Component Type: unsigned_short

[jdrozd at trumpet DicomImageReadPrintTags]$ ./DicomImageReadPrintTags
outsubject5.dcm
(0002|0000) Group Length =
194
(0002|0001) File Meta Information Version =
AAE=
(0002|0002) Media Storage SOP Class UID =
1.2.840.10008.5.1.4.1.1.7
(0002|0003) Media Storage SOP Instance UID =
1.2.826.0.1.3680043.2.1143.8995209879494441053058872310646575724
(0002|0010) Transfer Syntax UID =
1.2.840.10008.1.2.1
(0002|0012) Implementation Class UID =
147.144.143.155
(0002|0013) Implementation Version Name = ITK/GDCM
1.2.4
(0008|0012) Instance Creation Date =
20091126
(0008|0013) Instance Creation Time =
150853
(0008|0016) SOP Class UID =
1.2.840.10008.5.1.4.1.1.7

(0008|0018) SOP Instance UID =
1.2.826.0.1.3680043.2.1143.8995209879494441053058872310646575724

(0008|0020) Study Date =
20091126

(0008|0030) Study Time =
150853

(0008|0050) Accession Number
=

(0008|0060) Modality =
OT

(0008|0064) Conversion Type =
SYN

(0008|0070) Manufacturer = GDCM Factory
(0008|0080) Institution Name = GDCM Hospital
(0008|0090) Referring Physician's Name =
(0010|0010) Patient's Name = GDCM^Patient
(0010|0020) Patient ID = GDCM ID
(0010|0030) Patient's Birth Date =
(0010|0040) Patient's Sex =
(0018|0088) Spacing Between Slices = 1.207500
(0018|1164) Imager Pixel Spacing = 0.945750\0.945750
(0020|000d) Study Instance UID =
1.2.826.0.1.3680043.2.1125.1.99663966693826559960117773595375861
(0020|000e) Series Instance UID =
1.2.826.0.1.3680043.2.1125.1.80656207154489419332286356071443484
(0020|0010) Study ID =
(0020|0011) Series Number =
(0020|0013) Instance Number =
(0020|0020) Patient Orientation = H\P
(0020|0032) Image Position (Patient) = 199.237503\0.000000\0.000000
(0020|0037) Image Orientation (Patient) =
0.000000\0.000000\1.000000\0.000000\1.000000\0.000000
(0028|0002) Samples per Pixel = 1
(0028|0004) Photometric Interpretation = MONOCHROME2
(0028|0008) Number of Frames = 166
(0028|0010) Rows = 256
(0028|0011) Columns = 256
(0028|0030) Pixel Spacing = 0.945750\0.945750
(0028|0100) Bits Allocated = 16
(0028|0101) Bits Stored = 16
(0028|0102) High Bit = 15
(0028|0103) Pixel Representation = 1
(7fe0|0000) Group Length = 21757964
Patient's Name (0010|0010)  is: GDCM^Patient
Performing Physician's Name (0008|1050): (No Value Found in File)
PixelType: scalar
Component Type: short

On Thu, Nov 26, 2009 at 2:44 PM, John Drozd <john.drozd at gmail.com> wrote:

> Hi Luis:
>
> Sorry for taking some time to get back to you. I took a break from my
> computer to refresh my mind so I did an hour of ice skating at our
> university hockey arena.  I only fell a few times.
>
> Here is the output that you requested:
>
> From the added std::cout statements to my code, I have:
>
> output from reader->GetOutput()->GetDirection()
> 0 0 1
> 0 1 0
> -1 0 0
>
> output from castFilter->GetOutput()->GetDirection()
> 0 0 1
> 0 1 0
> -1 0 0
>
> output from connectedThreshold->GetOutput()->GetDirection()
> 0 0 1
> 0 1 0
> -1 0 0
>
> output from caster->GetOutput()->GetDirection()
> 0 0 1
> 0 1 0
> -1 0 0
>
> Also here are the tag statements from running that you requested:
> *(I get a segmentation fault when I run this program on the output image
> and I'm trying to figure out why it seg faults on the output image)*
>
>
> [jdrozd at trumpet DicomImageReadPrintTags]$ ./DicomImageReadPrintTags
> correctedsubject5.dcm
> (0002|0000) Group Length =
> 214
> (0002|0001) File Meta Information Version =
> AAE=
> (0002|0002) Media Storage SOP Class UID =
> 1.2.840.10008.5.1.4.1.1.2
> (0002|0003) Media Storage SOP Instance UID =
> 1.2.826.0.1.3680043.2.1125.1.10607669833050788267094246636093811
> (0002|0010) Transfer Syntax UID =
> 1.2.840.10008.1.2.1
> (0002|0012) Implementation Class UID =
> 147.144.143.155
> (0002|0013) Implementation Version Name = ITK/GDCM
> 1.2.4
> (0002|0016) Source Application Entity Title =
> NOTSPECIFIED
> (0008|0008) Image Type =
> DERIVED\PRIMARY
>
> (0008|0012) Instance Creation Date =
> 20091029
> (0008|0013) Instance Creation Time =
> 135224
> (0008|0016) SOP Class UID =
> 1.2.840.10008.5.1.4.1.1.2
>
> (0008|0018) SOP Instance UID =
> 1.2.826.0.1.3680043.2.1125.1.10607669833050788267094246636093811
>
> (0008|0020) Study Date =
> 20081030
>
> (0008|0030) Study Time =
> 164348.940
>
> (0008|0050) Accession Number
> =
>
> (0008|0060) Modality =
> CT
>
> (0008|0064) Conversion Type =
> WSD
>
> (0008|0070) Manufacturer =
> Manifacturer
>
> (0008|0080) Institution Name = GDCM
> Hospital
> (0008|0090) Referring Physician's Name = Refering
> Phisician
> (0010|0010) Patient's Name = Patient
> 188858520
> (0010|0020) Patient ID =
> 1747233212
>
> (0010|0030) Patient's Birth Date =
> 19500101
> (0010|0040) Patient's Sex =
> M
>
> (0018|0088) Spacing Between Slices = 1.207500
> (0018|1164) Imager Pixel Spacing = 0.945750\0.945750
> (0020|000d) Study Instance UID =
> 1.2.826.0.1.3680043.2.1125.1.53653479342656887425609263146205769
> (0020|000e) Series Instance UID =
> 1.2.826.0.1.3680043.2.1125.1.47155241092896696198844159625679986
> (0020|0010) Study ID = 1533117581
> (0020|0011) Series Number = 2135500125
> (0020|0013) Instance Number = 165
> (0020|0020) Patient Orientation = L\P
> (0020|0032) Image Position (Patient) = 199.237496852874\0.0\0.0
> (0020|0037) Image Orientation (Patient) = 0.0\0.0\-1.0\0.0\1.0\0.0
> (0020|4000) Image Comments = NOT FOR CLINICAL USE
> (0028|0002) Samples per Pixel = 1
> (0028|0004) Photometric Interpretation = MONOCHROME2
> (0028|0008) Number of Frames = 166
> (0028|0010) Rows = 256
> (0028|0011) Columns = 256
> (0028|0030) Pixel Spacing = 0.945750\0.945750
> (0028|0034) Pixel Aspect Ratio = 1\1
> (0028|0100) Bits Allocated = 16
> (0028|0101) Bits Stored = 16
> (0028|0102) High Bit = 15
> (0028|0103) Pixel Representation = 0
> (0028|1052) Rescale Intercept = 0.0
> (0028|1053) Rescale Slope = 1.0
> (0028|1054) Rescale Type = US
> (7fe0|0000) Group Length = 21757964
> Patient's Name (0010|0010)  is: Patient 188858520
> Performing Physician's Name (0008|1050): (No Value Found in File)
> PixelType: scalar
> Component Type: unsigned_short
>
> [jdrozd at trumpet DicomImageReadPrintTags]$ ./DicomImageReadPrintTags
> outsubject5.dcm
> Segmentation fault
> [jdrozd at trumpet DicomImageReadPrintTags]$
>
> Thanks,
> john
>
>
>
> On Thu, Nov 26, 2009 at 1:27 PM, Luis Ibanez <luis.ibanez at kitware.com>wrote:
>
>> Hi John,
>>
>> Please use the program:
>>
>>    Insight/Examples/IO/DicomImageReadPrintTags.cxx
>>
>> To print the DICOM tags of both the input and output images.
>>
>> Look for the string:
>>
>>                  (0020|0037) Image Orientation (Patient)
>>
>> and post the values (for both images) to the mailing list.
>>
>> They should have a look similar to:
>>
>> (0020|0037) Image Orientation (Patient) =
>> 0.9983222\0.02102422\0.05395257\-0.02105488\0.9997783\1.490116e-08
>>
>> ----
>>
>>
>> Also add the following print out statements to your code:
>>
>> std::cout << reader->GetOutput()->GetDirection() << std::endl;
>> std::cout << casterFilter->GetOutput()->GetDirection() << std::endl;
>> std::cout << connectedThreshold->GetOutput()->GetDirection() << std::endl;
>> std::cout << caster->GetOutput()->GetDirection() << std::endl;
>>
>> after the call to
>>
>>                writer->Update();
>>
>>
>> In this way we could sort out at what level of the process
>> the Direction information is being lost.
>>
>>
>>     Thanks,
>>
>>
>>            Luis
>>
>>
>>
>> ----------------------------------------------------------------------------
>> On Thu, Nov 26, 2009 at 12:57 PM, John Drozd <john.drozd at gmail.com>
>> wrote:
>> > Hello,
>> >
>> > Can anyone please tell me why my connect threshold segmentation code,
>> where
>> > I input a 3d dicom brain volume and output a 3d dicom ventricle
>> > segmentation, gives me my segmentation "upside down" (relative to the
>> > original inputted image) when I view it in 3D Slicer?  When I output the
>> > code in any other format eg. .mhd, the segmentation is right side up.
>> >
>> > Thank you.
>> >
>> > john
>> >
>> > Below is my uncommented code:
>> >
>> > /*
>> > to run type:
>> > ./ConnectedThresholdImageFilter correctedsubject5.dcm outsubject5.dcm
>> 103
>> > 142 95 17100 17300
>> > */
>> >
>> > #if defined(_MSC_VER)
>> > #pragma warning ( disable : 4786 )
>> > #endif
>> >
>> > #ifdef __BORLANDC__
>> > #define ITK_LEAN_AND_MEAN
>> > #endif
>> >
>> >
>> > #include "itkConnectedThresholdImageFilter.h"
>> >
>> > #include "itkImage.h"
>> > #include "itkCastImageFilter.h"
>> >
>> > #include "itkCurvatureFlowImageFilter.h"
>> >
>> > #include "itkImageFileReader.h"
>> > #include "itkImageFileWriter.h"
>> >
>> > #include "itkGDCMImageIO.h"
>> >
>> > #include "itkVersion.h"
>> >
>> > #include "itkOrientedImage.h"
>> > #include "itkMinimumMaximumImageFilter.h"
>> >
>> > #include "itkGDCMImageIO.h"
>> > #include "itkGDCMSeriesFileNames.h"
>> > #include "itkNumericSeriesFileNames.h"
>> >
>> > #include "itkImageSeriesReader.h"
>> > #include "itkImageSeriesWriter.h"
>> >
>> > #include "itkResampleImageFilter.h"
>> > #include "itkShiftScaleImageFilter.h"
>> >
>> > #include "itkIdentityTransform.h"
>> > #include "itkLinearInterpolateImageFunction.h"
>> >
>> > #include <itksys/SystemTools.hxx>
>> >
>> > #include "gdcm/src/gdcmFile.h"
>> > #include "gdcm/src/gdcmUtil.h"
>> >
>> > #include <string>
>> >
>> > int main( int argc, char *argv[])
>> > {
>> >   if( argc < 7 )
>> >     {
>> >     std::cerr << "Missing Parameters " << std::endl;
>> >     std::cerr << "Usage: " << argv[0];
>> >     std::cerr << " inputImage  outputImage seedX seedY seedZ
>> lowerThreshold
>> > upperThreshold" << std::endl;
>> >
>> >     return 1;
>> >     }
>> >
>> >   typedef   float           InternalPixelType;
>> >
>> >   const     unsigned int    Dimension = 3;
>> >
>> >   typedef itk::Image< InternalPixelType, Dimension >  InternalImageType;
>> >
>> >   typedef signed short OutputPixelType;
>> >
>> >   typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
>> >   typedef itk::Image< float, Dimension > OutputImageType2;
>> >   typedef itk::CastImageFilter< InternalImageType, OutputImageType >
>> >     CastingFilterType;
>> >   CastingFilterType::Pointer caster = CastingFilterType::New();
>> >
>> >   const    unsigned int    ImageDimension = 3;
>> >   typedef  signed short    PixelType;
>> >
>> >   typedef itk::Image< PixelType, ImageDimension >  FixedImageType;
>> >   typedef itk::Image< float, ImageDimension >  FloatImageType;
>> >
>> >   typedef  itk::ImageFileReader< FixedImageType > ReaderType;
>> >   typedef  itk::ImageFileWriter<  OutputImageType  > WriterType;
>> >   typedef  itk::ImageFileWriter<  FloatImageType  > WriterType2;
>> >
>> >   ReaderType::Pointer reader = ReaderType::New();
>> >   WriterType::Pointer writer = WriterType::New();
>> >   WriterType2::Pointer writer2 = WriterType2::New();
>> >
>> >   typedef itk::GDCMImageIO           ImageIOTypefixed;
>> >   ImageIOTypefixed::Pointer gdcmImageIOfixed = ImageIOTypefixed::New();
>> >   reader->SetImageIO( gdcmImageIOfixed );
>> >
>> >   typedef itk::GDCMImageIO           ImageIOTypefixed2;
>> >   ImageIOTypefixed2::Pointer gdcmImageIOfixed2 =
>> ImageIOTypefixed2::New();
>> >
>> >   reader->SetFileName( argv[1] );
>> >
>> >   reader->Update();
>> >
>> >   typedef itk::CurvatureFlowImageFilter< InternalImageType,
>> > InternalImageType >
>> >     CurvatureFlowImageFilterType;
>> >
>> >   CurvatureFlowImageFilterType::Pointer smoothing =
>> >                          CurvatureFlowImageFilterType::New();
>> >
>> >   typedef itk::ConnectedThresholdImageFilter< InternalImageType,
>> >                                     InternalImageType >
>> ConnectedFilterType;
>> >
>> >   ConnectedFilterType::Pointer connectedThreshold =
>> > ConnectedFilterType::New();
>> >
>> >   typedef signed short InputAPixelType;
>> >   typedef float OutputBPixelType;
>> >
>> >   typedef itk::Image< InputAPixelType, 3 > InputAImageType;
>> >   typedef itk::Image< OutputBPixelType, 3 > OutputBImageType;
>> >
>> >   typedef itk::CastImageFilter< InputAImageType, OutputBImageType >
>> > CastFilterType;
>> >
>> >   CastFilterType::Pointer castFilter = CastFilterType::New();
>> >
>> >
>> >   castFilter->SetInput( reader->GetOutput() );
>> >
>> >
>> >   connectedThreshold->SetInput( castFilter->GetOutput() );
>> >
>> >   caster->SetInput( connectedThreshold->GetOutput() );
>> >
>> >
>> >   smoothing->SetNumberOfIterations( 20 ); //was 5
>> >   smoothing->SetTimeStep( 0.125 );
>> >
>> >   const InternalPixelType lowerThreshold = atof( argv[6] );
>> >   const InternalPixelType upperThreshold = atof( argv[7] );
>> >
>> >   connectedThreshold->SetLower(  lowerThreshold  );
>> >   connectedThreshold->SetUpper(  upperThreshold  );
>> >
>> >   connectedThreshold->SetReplaceValue( 255 );
>> >
>> >   InternalImageType::IndexType  index;
>> >
>> >   index[0] = atoi( argv[3] );
>> >   index[1] = atoi( argv[4] );
>> >
>> >   //added
>> >   index[2] = atoi( argv[5] );
>> >
>> >   std::cout << index << std::endl;
>> >
>> >   // Software Guide : BeginCodeSnippet
>> >   connectedThreshold->SetSeed( index );
>> >
>> >   //obtain a 5 x 5 bounding region of seeds
>> >   int ii, jj, kk;
>> >
>> >   ii = index[0];
>> >   jj = index[1];
>> >   kk = index[2];
>> >
>> >   for (int i = ii; i < ii + 5; i++)
>> >     for (int j = jj; j < jj + 5; j++)
>> >       for (int k = kk; k < kk + 5; k++)
>> >     {
>> >
>> >       index[0] = i;
>> >       index[1] = j;
>> >       index[2] = k;
>> >       connectedThreshold->AddSeed( index );
>> >     }
>> >
>> >   for (int i = ii; i > ii - 5; i--)
>> >     for (int j = jj; j > jj - 5; j--)
>> >       for (int k = kk; k > kk - 5; k--)
>> >     {
>> >
>> >       index[0] = i;
>> >       index[1] = j;
>> >       index[2] = k;
>> >       connectedThreshold->AddSeed( index );
>> >     }
>> >
>> >   connectedThreshold->Print(std::cout,17100);
>> >
>> >
>> >
>> >   typedef itk::MetaDataDictionary DictionaryType;
>> >
>> >   DictionaryType inputdict = reader->GetMetaDataDictionary();
>> >
>> >   writer->SetMetaDataDictionary( inputdict );
>> >
>> >   writer->SetFileName( argv[2] );
>> >
>> >   writer->SetInput( caster->GetOutput() );
>> >
>> >   try
>> >     {
>> >     writer->Update();
>> >     }
>> >   catch( itk::ExceptionObject & excep )
>> >     {
>> >     std::cerr << "Exception caught !" << std::endl;
>> >     std::cerr << excep << std::endl;
>> >     }
>> >
>> >   return 0;
>> > }
>> >
>> >
>> > _____________________________________
>> > Powered by www.kitware.com
>> >
>> > Visit other Kitware open-source projects at
>> > http://www.kitware.com/opensource/opensource.html
>> >
>> > Kitware offers ITK Training Courses, for more information visit:
>> > http://www.kitware.com/products/protraining.html
>> >
>> > Please keep messages on-topic and check the ITK FAQ at:
>> > http://www.itk.org/Wiki/ITK_FAQ
>> >
>> > Follow this link to subscribe/unsubscribe:
>> > http://www.itk.org/mailman/listinfo/insight-users
>> >
>> >
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20091126/b208d1e5/attachment-0001.htm>


More information about the Insight-users mailing list