[Insight-users] itk::ImageIORegion::IndexType
camille le men
camillelemen at hotmail.com
Mon Dec 5 10:06:09 EST 2005
Answering myself, it seems I used setsize and setindex the same way the ones
of itk::Image are used, and it seems the use is different.
I now do not get any compilation nor executing error anymore but the image
I get in output is all black... Hope I'll see the error I did.
I defined the ioregion as follows:
itk::ImageIORegion ioregion;
ioregion.SetSize( 0,2000);
ioregion.SetSize(1,3000);
ioregion.SetIndex( 0,0 );
ioregion.SetIndex( 1,0);
Sorry for disturbing!!
Camille.
>From: "camille le men" <camillelemen at hotmail.com>
>To: insight-users at itk.org
>Subject: [Insight-users] itk::ImageIORegion::IndexType
>Date: Mon, 05 Dec 2005 14:56:19 +0100
>
>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/
>
>_______________________________________________
>Insight-users mailing list
>Insight-users at itk.org
>http://www.itk.org/mailman/listinfo/insight-users
_________________________________________________________________
Tout savoir sur la sécurité de vos enfants sur Internet !
http://go.msn.fr/10-channel/80-security/protection/default.asp
More information about the Insight-users
mailing list