[Insight-users] itk::ImageIORegion::IndexType

camille le men camillelemen at hotmail.com
Mon Dec 5 08:56:19 EST 2005


Hi everybody!
I want to read raw images. That is a file with no header. So, for the reader 
to be able to read it, I need to provide it the size of my images. In order 
to do so, I want to use the SetIORegion(IORegion) of ImageIOBase. So I need 
to define the size and index of the IORegion to be able to pass it as an 
argument of SetIORegion. I did that, the coresponding code is at the end of 
the mail, But, I get a Segmentation fault error at the execution time. It 
seems that the error is between those two lines: 
itk::ImageIORegion::IndexType start;//std::cout works
start[0] = 0;//std::cout doesn't work
It must be a problem like: I did not well initialize "start", and since it 
does not know how much space it needs for it, it does not reserve enough and 
it overwrites memory or sthing like that. (Am I right so far? Please tell me 
if U doubt!!) but I don't know how to do it, since there is no dynamic 
constructor of it.
I give U my code:

#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkRawImageIO.h"
#include "itkImageIOBase.h"
#include<iostream>
#include "itkImage.h"
#include "itkCastImageFilter.h"
#include "itkPNGImageIO.h"
int main( int argc, char ** argv )
{
if( argc < 3 )
   {
   std::cerr << "Usage: " << std::endl;
   std::cerr << argv[0] << " inputImageFile  outputImageFile " << std::endl;
   return EXIT_FAILURE;
   }
typedef unsigned short      PixelType;
const   unsigned int        Dimension = 2;
typedef itk::Image< PixelType, Dimension >    ImageType;
typedef unsigned char      PixelTypeOut;
typedef itk::Image< PixelTypeOut, Dimension >    ImageTypeOut;
typedef itk::ImageFileReader< ImageType >  ReaderType;
typedef itk::ImageFileWriter< ImageTypeOut >  WriterType;
typedef itk::RawImageIO<PixelType,Dimension> ImageIOType;
typedef itk::PNGImageIO ImageIOTypeOut;
typedef itk::CastImageFilter<ImageType,ImageTypeOut> CasterType;
//typedef itk::ImageIORegion IORegionType;
ImageIOType::Pointer RawIO = ImageIOType::New();
RawIO->SetPixelType(itk::ImageIOBase::SCALAR);
RawIO->SetNumberOfDimensions(2);
RawIO->SetDimensions(0,3000);
RawIO->SetDimensions(1,2000);
RawIO->SetComponentType(itk::ImageIOBase::USHORT);

RawIO->SetByteOrderToBigEndian();
RawIO->SetFileTypeToASCII();
ImageIOTypeOut::Pointer RawIOOut = ImageIOTypeOut::New();
RawIOOut->SetPixelType(itk::ImageIOBase::SCALAR);
RawIOOut->SetNumberOfDimensions(2);
RawIOOut->SetDimensions(0,3000);
RawIOOut->SetDimensions(1,2000);
RawIOOut->SetComponentType(itk::ImageIOBase::UCHAR);

itk::ImageIORegion::IndexType start;//cout works
start[0] = 0;//cout  does not work
start[1] = 0;
itk::ImageIORegion::SizeType size;

size[0] = 300;
size[1] = 400;
itk::ImageIORegion ioregion;

ioregion.SetSize(  size  );
ioregion.SetIndex( start );

RawIOOut->SetIORegion(ioregion);

ReaderType::Pointer reader = ReaderType::New();
WriterType::Pointer writer = WriterType::New();

reader->SetImageIO( RawIO );
writer->SetImageIO( RawIOOut);

const char * inputFilename  = argv[1];
const char * outputFilename = argv[2];

CasterType::Pointer caster = CasterType::New();

reader->SetFileName( inputFilename  );
writer->SetFileName( outputFilename );
caster->SetInput( reader->GetOutput() );
writer->SetInput( caster->GetOutput() );


try
   {
   writer->Update();
   }
catch( itk::ExceptionObject & err )
   {
   std::cerr << "ExceptionObject caught !" << std::endl;
   std::cerr << err << std::endl;
   return EXIT_FAILURE;
   }


return EXIT_SUCCESS;
}

--

ERROR: Segmentation Fault

_________________________________________________________________
Gagnez des super micro casques Logitech avec Allô Messenger Quizz !  
http://www.allomessengerquizz.com/



More information about the Insight-users mailing list