Hi guys,<br><br>I am trying to convert the AnatomicalOrientation of a 3D MRI from RPI to RSA using OrientImageFilter. <br><br><br>However, the entry "AnatomicalOrientation" in the header of the output *mha file is always RPI. itkSNAP was not able to interpret the anatomical orientation as RSA either.
<br><br>so my question is:<br><br>1. is it a bug in OrientImageFilter?<br><br>2. How to verify the AnatomicalOrientation of a *.nii or *.mha file? should I look at the header of meta data? or load them into Slicer3 or SNAP?
<br><br>The data can be accessed at <a href="http://www.duke.edu/~kurtzhao/RPI.zip">http://www.duke.edu/~kurtzhao/RPI.zip</a><br>The code is enclosed:<br><br>Thanks a lot!<br>-Kurt<br><br><br>#include <iostream><br>
<br><br>#include <metaCommand.h><br>#include <itkImageFileWriter.h><br>#include <itkImageFileReader.h><br>#include <itkAnalyzeImageIO.h><br>#include <itkNiftiImageIO.h><br>#include <itkOrientImageFilter.h
><br>#include <itkSpatialOrientation.h><br><br><br><br>int main(int argc, char **argv)<br> {<br><br> /** <br> * Typedefs and test reading to determine correct image types.<br> * *******************************************************************
<br> */<br><br> /** Initial image type. */<br> const unsigned int Dimension = 3;<br> //typedef float PixelType;<br> typedef short PixelType;<br><br> /** Some typedef's. */<br> typedef itk::Image< PixelType, Dimension > ImageType;
<br> typedef itk::ImageFileReader< ImageType > ReaderType;<br> typedef itk::ImageIOBase ImageIOBaseType;<br><br> ReaderType::Pointer reader = ReaderType::New();<br><br> itk::AnalyzeImageIO::Pointer io = itk::AnalyzeImageIO::New();
<br><br> //reader -> SetImageIO ( io ) ;<br> /** Setup the Reader. */<br> std::string inputFileName; <br> //inputFileName = "C:/data/formatConversion/c1002a3T1.hdr";<br> inputFileName = "C:/data/formatConversion/RPI.mha";
<br><br> reader->SetFileName( inputFileName.c_str() );<br><br> /** Generate all information. <br> reader->GenerateOutputInformation();<br><br> ImageIOBaseType::Pointer testImageIOBase = testReader->GetImageIO();
<br><br> unsigned int inputDimension = testImageIOBase->GetNumberOfDimensions();<br> unsigned int numberOfComponents = testImageIOBase->GetNumberOfComponents();<br> std::string inputPixelComponentType = testImageIOBase->GetComponentTypeAsString(
<br> testImageIOBase->GetComponentType() );<br> std::cout<<inputPixelComponentType<<std::endl;<br> std::string pixelType = testImageIOBase->GetPixelTypeAsString(<br> testImageIOBase->GetPixelType() );
<br> std::cout<<pixelType<<std::endl;<br><br> std::string outputPixelComponentType = inputPixelComponentType;<br> */<br><br> try <br> {<br> reader -> Update ( ) ;<br> }<br> catch( itk::ExceptionObject & err )
<br> {<br> std::cerr << "ExceptionObject caught !" << std::endl;<br> std::cerr << err << std::endl;<br> return EXIT_FAILURE;<br> }<br><br> typedef itk::OrientImageFilter<ImageType,ImageType> OrienterType;
<br> OrienterType::Pointer orienter = OrienterType::New();<br> orienter->UseImageDirectionOn();<br> //orienter->SetDesiredCoordinateOrientation(itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_LPS); <br> orienter->SetDesiredCoordinateOrientation(itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_RSA);
<br> //orienter->SetDesiredCoordinateOrientation(itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_RPI); <br> orienter->SetInput( reader -> GetOutput ( ) );<br> try <br> {<br> orienter->Update();<br>
}<br> catch( itk::ExceptionObject & err )<br> {<br> std::cerr << "ExceptionObject caught !" << std::endl;<br> std::cerr << err << std::endl;<br> return EXIT_FAILURE;
<br> }<br><br> typedef itk::ImageFileWriter < ImageType > WriterType;<br><br> WriterType::Pointer writer = WriterType::New();<br><br> itk::NiftiImageIO::Pointer niftIio = itk::NiftiImageIO::New();<br><br>
//writer -> SetImageIO ( niftIio ) ;<br><br> std::string outputFileName; <br><br> outputFileName = "C:/data/formatConversion/RSA.mha";<br> //outputFileName = "C:/data/formatConversion/LPS.mha";
<br> //outputFileName = "C:/data/formatConversion/RPI.mha";<br><br> writer ->SetFileName( outputFileName.c_str() );<br><br> //writer -> SetInput ( reader -> GetOutput ( ) ) ;<br> writer -> SetInput ( orienter -> GetOutput ( ) ) ;
<br><br> writer -> UseCompressionOn ( ) ;<br><br> try <br> {<br> writer -> Update ( ) ;<br> }<br> catch( itk::ExceptionObject & err )<br> {<br> std::cerr << "ExceptionObject caught !" << std::endl;
<br> std::cerr << err << std::endl;<br> return EXIT_FAILURE;<br> }<br><br> return EXIT_SUCCESS;<br> }<br>