[Insight-users] permuting and writing DICOM series Problem

MX dammyxxx at web.de
Wed Aug 16 11:00:47 EDT 2006


Hello list,
i have a problem with reading, permuting and writing a DICOM series,
please excuse but my english is not the best.
I'm trying to write a little application for transforming DICOM Images.
My Problem occurs if I load a DICOM series , permute it around and then
try to give the SeriesWriter the MetaDataDictionaryArray from the 
SeriesReader,

    seriesWriter->SetMetaDataDictionaryArray( 
seriesReader->GetMetaDataDictionaryArray() );

The problem does not come up if there's no permuting process.

Did anybody ever had this problem and/or knows what to do?

Thx,
Martin
PS: I copied from my code to a simple example to show the problem:

#include <itkImageSeriesWriter.h>
#include <itkImageSeriesReader.h>
#include <itkGDCMImageIO.h>
#include <itkGDCMSeriesFileNames.h>
#include <itkNumericSeriesFileNames.h>
#include <itkPermuteAxesImageFilter.h>
#include <string.h>

using namespace std;
int main( int argc, char **argv ) {
   
    typedef itk::Image< short, 2> s2ImageType;
    typedef itk::Image< short, 3> s3ImageType;
    
    typedef itk::ImageSeriesReader<s3ImageType> SeriesReaderType;      
    SeriesReaderType::Pointer seriesReader = SeriesReaderType::New();
       
    typedef itk::GDCMImageIO DicomIOType;
    DicomIOType::Pointer dicomIO = DicomIOType::New();
   
    vector< string > *fileNames = new vector< string >;
   
    for ( int i=1; i<argc-1; i++ ){
        fileNames->push_back( string( argv[i] ) );
    }
       
    seriesReader->SetFileNames( (*fileNames) );
    seriesReader->SetImageIO( dicomIO );   
    s3ImageType::Pointer image = seriesReader->GetOutput();

    try {
        cout << "reading...";
        image->Update();       
    } catch( itk::ExceptionObject & ex ) {
        cout << ex << endl;
        delete fileNames;
        return 0;
    }
   
    cout << "done" << endl;
   
   
    typedef itk::PermuteAxesImageFilter< s3ImageType > 
PermuteAxesImageFilterType;     
    PermuteAxesImageFilterType::Pointer permuteAxesFilter = 
PermuteAxesImageFilterType::New();
    permuteAxesFilter->SetInput( image );
   
    typedef itk::FixedArray< signed short, 3> FixedArrayType;
    FixedArrayType dimensionArray;
    dimensionArray[0] = permuteAxesFilter->GetOrder()[2];
    dimensionArray[1] = permuteAxesFilter->GetOrder()[0];
    dimensionArray[2] = permuteAxesFilter->GetOrder()[1];
    permuteAxesFilter->SetOrder( dimensionArray );
   
    image = permuteAxesFilter->GetOutput();
   
    try {
        cout << "permuting...";
        image->Update();
    } catch( itk::ExceptionObject & ex ) {
        cout << ex << endl;
        delete fileNames;
        return 0;
    }
          
    s3ImageType::RegionType region = image->GetLargestPossibleRegion();
    s3ImageType::IndexType start = region.GetIndex();
    s3ImageType::SizeType size = region.GetSize();
   
    image->SetRequestedRegion( region );
    const unsigned int firstSlice = start[2] +1 ;
    const unsigned int lastSlice = start[2] + size[2];
   
    string format = "D:\\projects\\daten\\output\\TestVolume-%04d.dcm";
   
    typedef itk::NumericSeriesFileNames NumericNamesGeneratorType;
   
    NumericNamesGeneratorType::Pointer numericNamesGenerator = 
NumericNamesGeneratorType::New();
   
    numericNamesGenerator->SetSeriesFormat( format.c_str() );
    numericNamesGenerator->SetStartIndex( firstSlice );
    numericNamesGenerator->SetEndIndex( lastSlice );
    numericNamesGenerator->SetIncrementIndex( 1 );
       
    typedef itk::ImageSeriesWriter < s3ImageType, s2ImageType > 
SeriesWriterType;
    SeriesWriterType::Pointer seriesWriter = SeriesWriterType::New();
   
    seriesWriter->SetInput( image );
    seriesWriter->SetMetaDataDictionaryArray( 
seriesReader->GetMetaDataDictionaryArray() );
   
    seriesWriter->SetImageIO( dicomIO );     
    seriesWriter->SetStartIndex( firstSlice );
    seriesWriter->SetIncrementIndex( 1 );
    seriesWriter->SetFileNames( numericNamesGenerator->GetFileNames() );
   
    try{
        cout << "writing...";
        seriesWriter->Update();
    } catch( itk::ExceptionObject &ex ){
        cout << ex << endl;       
    }
    cout << "done" << endl;
   
    delete fileNames;
   
    return 0;
}





More information about the Insight-users mailing list