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

Luis Ibanez luis.ibanez at kitware.com
Thu Nov 26 13:27:05 EST 2009


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
>
>


More information about the Insight-users mailing list