<div dir="ltr">Hi all,<br><br>I did a little program to read a 3D Medical Image in Anaylze format and extract a slice, saving it in 2D, using the same format.<br><br>It works for almost all of the images I have here, but with one I had a bad result.<br>
<br>Here are 2 images that I have tested: <a href="http://www.vision.ime.usp.br/~luisrpp/analyze/">http://www.vision.ime.usp.br/~luisrpp/analyze/</a><br><br>With the 061b0105_anlz.hdr, it works fine. But with the s9.hdr, I have got an unaligned image.<br>
<br>When I tryied to write a 2D image slice from s9.hdr, the following message was displayed:<br><br>"AnalyzeImageIO (0x8153950): ERROR: Analyze 7.5 File Format Only Allows RPI, PIR, and RIP Orientation"<br><br>
Using an Medical Image Viwer program, I discovered that the image s9.hdr has an IRA Orientation. I used then an OrientImageFilter to fix this. But it didn't work. The following message was displayed:<br><br>"terminate called after throwing an instance of 'itk::InvalidRequestedRegionError'<br>
what(): /home/luis/dev-tools/InsightToolkit-3.2.0/Code/Common/itkDataObject.cxx:397:<br>Requested region is (at least partially) outside the largest possible region.<br>Aborted"<br><br>Does anybody knows how to solve this problem?<br>
<br>This is par of the code (without validations):<br><br>-------------------------------------------------------------------------------------------------------------------------------------------------------<br>#include "itkImageFileReader.h"<br>
#include "itkImageFileWriter.h"<br>#include "itkExtractImageFilter.h"<br>#include "itkImage.h"<br>#include "itkAnalyzeImageIO.h"<br>#include "itkOrientImageFilter.h"<br>#include<sys/stat.h><br>
<br>typedef float InputPixelType4D;<br>typedef float OutputPixelType3D;<br><br>typedef itk::Image< InputPixelType4D, 4 > InputImageType4D;<br>typedef itk::Image< OutputPixelType3D, 3 > OutputImageType3D;<br>
<br>typedef itk::ImageFileReader< InputImageType4D > ReaderType4D;<br>typedef itk::ImageFileWriter< OutputImageType3D > WriterType3D;<br>typedef itk::ExtractImageFilter< InputImageType4D, OutputImageType3D > FilterType3D;<br>
<br>typedef float InputPixelType3D;<br>typedef float OutputPixelType2D;<br><br>typedef itk::Image< InputPixelType3D, 3 > InputImageType3D;<br>typedef itk::Image< OutputPixelType2D, 2 > OutputImageType2D;<br>
<br>typedef itk::ImageFileReader< InputImageType3D > ReaderType3D;<br>typedef itk::ImageFileWriter< OutputImageType2D > WriterType2D;<br>typedef itk::ExtractImageFilter< InputImageType3D, OutputImageType2D > FilterType2D;<br>
<br>typedef float PixelType;<br>typedef itk::Image< PixelType, 2 > InputImageType;<br>typedef itk::ImageFileReader< InputImageType > ReaderType;<br><br>InputImageType::Pointer extract2DImageSlice(InputImageType3D::Pointer reader, int plane, int slice) {<br>
FilterType2D::Pointer filter = FilterType2D::New();<br> <br> InputImageType3D::RegionType inputRegion =<br> reader->GetLargestPossibleRegion();<br> <br> InputImageType3D::SizeType size = inputRegion.GetSize();<br>
size[plane] = 0;<br> <br> InputImageType3D::IndexType start = inputRegion.GetIndex();<br> const unsigned int sliceNumber = slice;<br> start[plane] = sliceNumber;<br> <br> InputImageType3D::RegionType desiredRegion;<br>
desiredRegion.SetSize( size );<br> desiredRegion.SetIndex( start );<br> <br> filter->SetExtractionRegion( desiredRegion );<br> <br> filter->SetInput( reader );<br><br> InputImageType::Pointer img = filter->GetOutput();<br>
img->Update();<br><br> return img;<br>}<br><br>InputImageType3D::Pointer ReadAnalyzeFile(const char *path)<br>{<br> itk::AnalyzeImageIO::Pointer io = itk::AnalyzeImageIO::New();<br> ReaderType3D::Pointer fileReader = ReaderType3D::New();<br>
fileReader->SetImageIO(io);<br> fileReader->SetFileName(path);<br> fileReader->Update();<br> InputImageType3D::Pointer rval = fileReader->GetOutput();<br> <br> itk::OrientImageFilter<InputImageType3D,InputImageType3D>::Pointer orienter =<br>
itk::OrientImageFilter<InputImageType3D,InputImageType3D>::New();<br> orienter->UseImageDirectionOn();<br> orienter->SetDesiredCoordinateOrientation(itk::SpatialOrientation::ITK_COORDINATE_ORIENTATION_IRA);<br>
orienter->SetInput(rval);<br> orienter->Update();<br> rval = orienter->GetOutput();<br><br> return rval;<br> }<br><br>int main( int argc, char ** argv )<br>{<br> if( argc < 2 )<br> {<br> std::cerr << "Usage: " << std::endl;<br>
std::cerr << argv[0] << " input3DImageFile " << std::endl;<br> return EXIT_FAILURE;<br> }<br><br> char *inputFilename = argv[1];<br><br> InputImageType3D::Pointer image = ReadAnalyzeFile(inputFilename);<br>
InputImageType::Pointer image2D = extract2DImageSlice(image, 0, 50);<br><br> WriterType2D::Pointer writer = WriterType2D::New();<br> writer->SetFileName( "teste.hdr" );<br> writer->SetInput( image2D );<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><br>-------------------------------------------------------------------------------------------------------------------------------------------------------<br>
<br>Thank's in advance,<br>Luis<br></div>