[Insight-users] How to merge dicom slices into one single 3D volume?

Abayiz abayiz at yahoo.com
Sat Jul 9 06:47:41 EDT 2011


Hello all,

I performed segmentation slice by slice, and saved them also slice by slice. Then while reading this series and writing them into one single '.mha' file, it only writes the first slice. I am using "DicomeSeriesReadImageWrite2.cxx" of the user-guide. Actually it works quite well with my other dicom data series. But with this one no. I can see my segmented data slice by slice in Matlab, which indicates they are written correctly. So I cannot figure out where the wrong part is. 

Here are the data types for segmenting and saving slice by slice that I've used:
******************************
typedef   float           InternalPixelType;
  const     unsigned int    Dimension = 3;
  typedef itk::Image< InternalPixelType, Dimension >  InternalImageType;
  typedef unsigned char                            OutputPixelType;
  typedef itk::Image< OutputPixelType, 3 > OutputImageType;
typedef  itk::ImageFileReader< InternalImageType > ReaderType;
  typedef  itk::ImageFileWriter<  OutputImageType  > WriterType;


*****************
And, here are the data types for reading the saved slices and writing them into one single file (which is in the DicomSeriesReadImageWrite2.cxx in the user guide):
***************

typedef signed short    PixelType;
  const unsigned int      Dimension = 3;
  typedef itk::OrientedImage< PixelType, Dimension >  ImageType;
  typedef itk::ImageSeriesReader< ImageType >   ReaderType;
  ReaderType::Pointer reader = ReaderType::New();
  typedef itk::GDCMImageIO       ImageIOType;
  ImageIOType::Pointer dicomIO = ImageIOType::New(); 
  reader->SetImageIO( dicomIO );
  typedef itk::GDCMSeriesFileNames NamesGeneratorType;
  NamesGeneratorType::Pointer nameGenerator = NamesGeneratorType::New();
  nameGenerator->SetUseSeriesDetails( true );
  nameGenerator->AddSeriesRestriction("0008|0021" );
  nameGenerator->SetDirectory( argv[1] );
    std::string seriesIdentifier;
    if( argc > 3 ) // If no optional series identifier
      {
      seriesIdentifier = argv[3];
      }
    else
      {
      seriesIdentifier = seriesUID.begin()->c_str();
      }
    typedef std::vector< std::string >   FileNamesContainer;
    FileNamesContainer fileNames;
    fileNames = nameGenerator->GetFileNames( seriesIdentifier );
    reader->SetFileNames( fileNames );
    try
      {
      reader->Update();
      }
    catch (itk::ExceptionObject &ex)
      {
      std::cout << ex << std::endl;
      return EXIT_FAILURE;
      }
    typedef itk::ImageFileWriter< ImageType > WriterType;
    WriterType::Pointer writer = WriterType::New();   
    writer->SetFileName( argv[2] );
    writer->SetInput( reader->GetOutput() );
****************

Thanks in advance.

Abayiz


More information about the Insight-users mailing list