[Insight-users] Need help with PermuteAxesImageFilter

MX dammyxxx at web.de
Mon Aug 28 13:41:37 EDT 2006


Hi Luis,
here's my code:
( if you comment the permutation part out, it should be nearly the 
typical example )

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

#include <string.h>

#include "HeaderReader.h"

int main( int argc, char **argv ) {
   
    typedef itk::Image< short, 2> s2ImageType;
    typedef itk::Image< short, 3> s3ImageType;
    typedef itk::ImageSeriesReader<s3ImageType> SeriesReaderType;
    typedef itk::GDCMImageIO DicomIOType;
    typedef itk::PermuteAxesImageFilter< s3ImageType > 
PermuteAxesImageFilterType;     
    typedef itk::FixedArray< signed short, 3> FixedArrayType;
    typedef itk::NumericSeriesFileNames NumericNamesGeneratorType;
    typedef itk::ImageSeriesWriter < s3ImageType, s2ImageType > 
SeriesWriterType;
   
    std::vector< std::string > fileNames;
   
    for ( int i=1; i<argc-1; i++ ){
        fileNames.push_back( std::string( argv[i] ) );
    }
   
   
    SeriesReaderType::Pointer seriesReader = SeriesReaderType::New();
    DicomIOType::Pointer dicomIO = DicomIOType::New();
    seriesReader->SetFileNames( fileNames );
    seriesReader->SetImageIO( dicomIO );
   
    try {
        seriesReader->Update();       
    } catch( itk::ExceptionObject & ex ) {
        std::cout << ex << std::endl;
        return 0;
    }
   
   
    PermuteAxesImageFilterType::Pointer permuteAxesFilter = 
PermuteAxesImageFilterType::New();
    permuteAxesFilter->SetInput( seriesReader->GetOutput() );
   
    FixedArrayType dimensionArray;
    dimensionArray[0] = permuteAxesFilter->GetOrder()[2];
    dimensionArray[1] = permuteAxesFilter->GetOrder()[0];
    dimensionArray[2] = permuteAxesFilter->GetOrder()[1];
    permuteAxesFilter->SetOrder( dimensionArray );
   
    try {
        permuteAxesFilter->Update();
    } catch( itk::ExceptionObject & ex ) {
        std::cout << ex << std::endl;
        return 0;
    }

    s3ImageType::Pointer image = permuteAxesFilter->GetOutput();
   
    s3ImageType::RegionType region = image->GetLargestPossibleRegion();
    s3ImageType::IndexType start = region.GetIndex();
    s3ImageType::SizeType size = region.GetSize();
   
    const unsigned int firstSlice = start[2] +1 ;
    const unsigned int lastSlice = start[2] + size[2];
    std::string format = "TestVolume-%04d.dcm";
   
    NumericNamesGeneratorType::Pointer numericNamesGenerator = 
NumericNamesGeneratorType::New();
    numericNamesGenerator->SetSeriesFormat( format.c_str() );
    numericNamesGenerator->SetStartIndex( firstSlice );
    numericNamesGenerator->SetEndIndex( lastSlice );
    numericNamesGenerator->SetIncrementIndex( 1 );
       
    SeriesWriterType::Pointer seriesWriter = SeriesWriterType::New();
    seriesWriter->SetImageIO( dicomIO );
    seriesWriter->SetInput( permuteAxesFilter->GetOutput() );
    seriesWriter->SetStartIndex( firstSlice );
    seriesWriter->SetIncrementIndex( 1 );
    seriesWriter->SetFileNames( numericNamesGenerator->GetFileNames() );
   
    try {
        seriesWriter->SetMetaDataDictionaryArray( 
seriesReader->GetMetaDataDictionaryArray() );
        seriesWriter->Update();
    } catch( itk::ExceptionObject &ex ){
        std::cout << ex << std::endl;       
    }
   
   
    return 0;
}

Thanks,
Martin




More information about the Insight-users mailing list