<span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; ">Hi,<br><br>I am new to ITK and I am trying to read the Analyse 7.5 image.<br>Its an image created by imageJ and is a 16 bit grayscale image of the<br>
dimension 512*512*24<br><br>I am getting a segmentation fault while doing reader1->update().<br>The code is a sample code which reads an image and writes it back. I am<br>using iterators because they will help manipulate the image for other<br>
purposes.<br><br>Heres the code.<br><br>#include "itkImage.h"<br>#include "itkImageRegionConstIterator.h"<br>#include "itkImageRegionIterator.h"<br>#include "itkImageFileReader.h"<br>
#include "itkImageFileWriter.h"<br>#include "itkRGBPixel.h"<br>#include "stdio.h"<br>using namespace std;<br><br>int main()<br>{<br> const unsigned char Dimension = 3;<br><br> typedef signed short PixelType;<br>
typedef itk::Image< PixelType, Dimension > ImageType;<br><br> typedef itk::ImageRegionConstIterator< ImageType > ConstIteratorType;<br> typedef itk::ImageRegionIterator< ImageType> IteratorType;<br>
<br> typedef itk::ImageFileReader< ImageType > ReaderType;<br> typedef itk::ImageFileWriter< ImageType > WriterType;<br><br> ImageType::RegionType inputRegion;<br><br> ImageType::RegionType::IndexType inputStart;<br>
// Imput image size<br> ImageType::RegionType::SizeType size_ip;<br> // Output image size<br> ImageType::RegionType::SizeType size_op;<br><br> inputStart[0] = 0;<br> inputStart[1] = 0;<br> inputStart[2] = 0;<br><br> size_ip[0] = 512;<br>
size_ip[1] = 512;<br> size_ip[2] = 24;<br><br> inputRegion.SetSize( size_ip );<br> inputRegion.SetIndex( inputStart );<br><br> ImageType::RegionType outputRegion;<br><br> ImageType::RegionType::IndexType outputStart;<br>
<br> outputStart[0] = 0;<br> outputStart[1] = 0;<br> outputStart[2] = 0;<br><br> outputRegion.SetSize( size_ip );<br> outputRegion.SetIndex( outputStart );<br><br><br> ReaderType::Pointer reader1 = ReaderType::New();<br> reader1->SetFileName( "psf-green-bead-35nm.img" );<br>
try<br> {<br> reader1->Update();<br> }<br> catch ( itk::ExceptionObject &err)<br> {<br> std::cerr << "ExceptionObject caught !" << std::endl;<br> std::cerr << err << std::endl;<br>
return -1;<br> }<br><br><br> ImageType::Pointer outputImage = ImageType::New();<br> outputImage->SetRegions( outputRegion );<br> const ImageType::SpacingType& spacing =<br>reader1->GetOutput()->GetSpacing();<br>
const ImageType::PointType& inputOrigin =<br>reader1->GetOutput()->GetOrigin();<br> double outputOrigin[ Dimension ];<br><br> for(unsigned int i=0; i< Dimension; i++)<br> {<br> outputOrigin[i] = inputOrigin[i] + spacing[i] * inputStart[i];<br>
}<br><br> outputImage->SetSpacing( spacing );<br> outputImage->SetOrigin( outputOrigin );<br> outputImage->Allocate();<br><br> ConstIteratorType inputIt1( reader1->GetOutput(), inputRegion );<br> IteratorType outputIt( outputImage,outputRegion );<br>
<br> inputIt1.GoToBegin();<br> outputIt.GoToBegin();<br><br> while( !inputIt1.IsAtEnd() )<br> {<br> outputIt.Set(inputIt1.Get());<br><br> ++inputIt1;<br> ++outputIt;<br> }<br><br> WriterType::Pointer writer = WriterType::New();<br>
writer->SetFileName("copy.img");<br> writer->SetInput( outputImage );<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 -1;<br> }<br><br><br>}<br><br><br>Can you please help?<br>Thank you in advance.</span>