[Insight-users] Reading Analyse 7.5 image
chaitanya chitale
chitale at cse.ohio-state.edu
Sat Mar 20 20:29:43 EDT 2010
Hi,
I am new to ITK and I am trying to read the Analyse 7.5 image.
Its an image created by imageJ and is a 16 bit grayscale image of the
dimension 512*512*24
I am getting a segmentation fault while doing reader1->update().
The code is a sample code which reads an image and writes it back. I am
using iterators because they will help manipulate the image for other
purposes.
Heres the code.
#include "itkImage.h"
#include "itkImageRegionConstIterator.h"
#include "itkImageRegionIterator.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkRGBPixel.h"
#include "stdio.h"
using namespace std;
int main()
{
const unsigned char Dimension = 3;
typedef signed short PixelType;
typedef itk::Image< PixelType, Dimension > ImageType;
typedef itk::ImageRegionConstIterator< ImageType > ConstIteratorType;
typedef itk::ImageRegionIterator< ImageType> IteratorType;
typedef itk::ImageFileReader< ImageType > ReaderType;
typedef itk::ImageFileWriter< ImageType > WriterType;
ImageType::RegionType inputRegion;
ImageType::RegionType::IndexType inputStart;
// Imput image size
ImageType::RegionType::SizeType size_ip;
// Output image size
ImageType::RegionType::SizeType size_op;
inputStart[0] = 0;
inputStart[1] = 0;
inputStart[2] = 0;
size_ip[0] = 512;
size_ip[1] = 512;
size_ip[2] = 24;
inputRegion.SetSize( size_ip );
inputRegion.SetIndex( inputStart );
ImageType::RegionType outputRegion;
ImageType::RegionType::IndexType outputStart;
outputStart[0] = 0;
outputStart[1] = 0;
outputStart[2] = 0;
outputRegion.SetSize( size_ip );
outputRegion.SetIndex( outputStart );
ReaderType::Pointer reader1 = ReaderType::New();
reader1->SetFileName( "psf-green-bead-35nm.img" );
try
{
reader1->Update();
}
catch ( itk::ExceptionObject &err)
{
std::cerr << "ExceptionObject caught !" << std::endl;
std::cerr << err << std::endl;
return -1;
}
ImageType::Pointer outputImage = ImageType::New();
outputImage->SetRegions( outputRegion );
const ImageType::SpacingType& spacing =
reader1->GetOutput()->GetSpacing();
const ImageType::PointType& inputOrigin =
reader1->GetOutput()->GetOrigin();
double outputOrigin[ Dimension ];
for(unsigned int i=0; i< Dimension; i++)
{
outputOrigin[i] = inputOrigin[i] + spacing[i] * inputStart[i];
}
outputImage->SetSpacing( spacing );
outputImage->SetOrigin( outputOrigin );
outputImage->Allocate();
ConstIteratorType inputIt1( reader1->GetOutput(), inputRegion );
IteratorType outputIt( outputImage,outputRegion );
inputIt1.GoToBegin();
outputIt.GoToBegin();
while( !inputIt1.IsAtEnd() )
{
outputIt.Set(inputIt1.Get());
++inputIt1;
++outputIt;
}
WriterType::Pointer writer = WriterType::New();
writer->SetFileName("copy.img");
writer->SetInput( outputImage );
try
{
writer->Update();
}
catch ( itk::ExceptionObject &err)
{
std::cerr << "ExceptionObject caught !" << std::endl;
std::cerr << err << std::endl;
return -1;
}
}
Can you please help?
Thank you in advance.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20100320/b8b0cab1/attachment.htm>
More information about the Insight-users
mailing list