[Insight-users] Writing a Colour Meta Image
Puja Malik
puja.malik@memot.unibe.ch
Thu, 07 Nov 2002 10:26:06 +0100
--Boundary_(ID_9gzYGM1gZhQ+MyS/JaCUpQ)
Content-type: text/plain; charset=iso-8859-1
Content-transfer-encoding: 8BIT
Hello,
I'm having some trouble writing a colour meta image. I am using
exactly the same format as the MetaImageWriterExample, except I have
declared my image with an RGB pixel type. The program compiles and
links, but fails at runtime as soon as the
ImageFileWriter::Write() function is called. I've had no problems when
writing to a grey image. I'm wondering what I'm doing wrong? Here is
my code:
typedef itk::Image<itk::RGBPixel<float>, 3> ImageType;
ImageType::SizeType imSize = {{256, 256, 10}};
ImageType::Pointer im = ImageType::New();
im->SetRegions(imSize);
im->Allocate();
//To set the pixels I declare a temporary RGB pixel variable and set
each pixel using an iterator:
itk::ImageRegionIterator< ImageType > it(im,
im->GetLargestPossibleRegion());
//create a temporary RGB pixel object to use to set each pixel
itk::RGBPixel<float> tempPix;
it.GoToBegin();
while(!it.IsAtEnd())
{
//sets in order Red, Green Blue
tempPix.SetRed(50);
tempPix.SetGreen(0);
tempPix.SetBlue(0);
it.Set(tempPix);
++it;
}
//>>>>>>>>>> Write the Image to a file <<<<<<<<<<<<<<<<<<<<<//
typedef itk::ImageFileWriter< ImageType > VolumeWriterType;
VolumeWriterType::Pointer writer = VolumeWriterType::New();
itk::MetaImageIO::Pointer metaWriter = itk::MetaImageIO::New();
writer->SetImageIO( metaWriter );
writer->SetFileName(fName);
writer->SetInput( im );
//>>>>>>>>>>>>>PROGRAM FAILS HERE<<<<<<<<<<<<<<<<<<//
writer->Write();
---------------------------------------
Puja Malik
M. E. Müller Institute for Biomechanics
University of Bern
P. O. Box 30
3010 Bern
Switzerland
Phone: +41-31-632-8730
Fax: +41-31-632-4951
Email: Puja.Malik@memot.unibe.ch
---------------------------------------
--Boundary_(ID_9gzYGM1gZhQ+MyS/JaCUpQ)
Content-type: text/html; charset=us-ascii
Content-transfer-encoding: 7BIT
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Hello,
<p>I'm having some trouble writing a colour meta image.
I am using exactly the same format as the MetaImageWriterExample, except
I have declared my image with an RGB pixel type. The program
compiles and links, but fails at runtime as soon as the ImageFileWriter::Write() function
is called. I've had no problems when writing to a grey image.
I'm wondering what I'm doing wrong? Here is my code:
<p> typedef itk::Image<itk::RGBPixel<float>, 3> ImageType;
<br> ImageType::SizeType imSize = {{256, 256, 10}};
<p> ImageType::Pointer im = ImageType::New();
<br> im->SetRegions(imSize);
<br> im->Allocate();
<p>//To set the pixels I declare a temporary RGB pixel variable
and set each pixel using an iterator:
<p> itk::ImageRegionIterator< ImageType > it(im,
<br> im->GetLargestPossibleRegion());
<br>
<br> //create a temporary RGB pixel object to use to set each pixel
<br> itk::RGBPixel<float> tempPix;
<p> it.GoToBegin();
<br>
<br> while(!it.IsAtEnd())
<br> {
<br> //sets in order Red, Green Blue
<br> tempPix.SetRed(50);
<br> tempPix.SetGreen(0);
<br> tempPix.SetBlue(0);
<br> it.Set(tempPix);
<br> ++it;
<br> }
<p>//>>>>>>>>>> Write the Image to a file <<<<<<<<<<<<<<<<<<<<<//
<br>
<br> typedef itk::ImageFileWriter< ImageType > VolumeWriterType;
<br> VolumeWriterType::Pointer writer = VolumeWriterType::New();
<p> itk::MetaImageIO::Pointer metaWriter = itk::MetaImageIO::New();
<br>
<br> writer->SetImageIO( metaWriter );
<br> writer->SetFileName(fName);
<br> writer->SetInput( im );
<p>//>>>>>>>>>>>>>PROGRAM FAILS HERE<<<<<<<<<<<<<<<<<<//
<br> writer->Write();
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<pre>
---------------------------------------
Puja Malik
M. E. Müller Institute for Biomechanics
University of Bern
P. O. Box 30
3010 Bern
Switzerland
Phone: +41-31-632-8730
Fax: +41-31-632-4951
Email: Puja.Malik@memot.unibe.ch
---------------------------------------</pre>
</html>
--Boundary_(ID_9gzYGM1gZhQ+MyS/JaCUpQ)--