[Insight-users] Can not wirte RGB image correctly

Fucang Jia jiafucang@hotmail.com
Tue, 21 Jan 2003 21:50:08 +0800


Hi, everyone,

Thank Luis for much help!

A writing RGB image error occurs in the following adapted 
ExtractImageRegion.cxx, the program can read color png or MetaImage, but 
write color image in a wrong way, it seems that the array order is 
misarranged. Could you tell me what's wrong with the code?

typedef itk::RGBPixel< unsigned char > PixelType;
typedef itk::Image<PixelType, 2> ImageType;

typedef itk::ImageFileReader< ImageType > ReaderType;
ReaderType::Pointer reader = ReaderType::New();

reader->SetFileName( argv[1] );

typedef itk::ExtractImageFilter< ImageType, ImageType > ExtractFilterType;
ExtractFilterType::Pointer extractor = ExtractFilterType::New();

extractor->SetInput( reader->GetOutput() );

ImageType::SizeType  size;
ImageType::IndexType index;

index[0] = atoi( argv[3] );
index[1] = atoi( argv[4] );

size[0] = atoi( argv[5] );
size[1] = atoi( argv[6] );

ImageType::RegionType region;
region.SetIndex( index );
region.SetSize( size );

extractor->SetExtractionRegion( region );

typedef itk::ImageFileWriter< ImageType > WriterType;
WriterType::Pointer writer = WriterType::New();

writer->SetFileName( argv[2] );

writer->SetInput( extractor->GetOutput() );

writer->Update();


Thanks a lot!

Fucang

_________________________________________________________________
MSN 8 helps eliminate e-mail viruses. Get 2 months FREE* 
http://join.msn.com/?page=features/virus