[Insight-users] RGB images from Visible Human Dataset
Stefan Lindenau
stefan . lindenau at gmx . de
Wed, 29 Oct 2003 14:58:17 -0500
Hello,
I have a problem to read the data of the Visible Human Dataset right
into ITK. I have just coded a little sample that reads the data of one
file via MetaIO and should write it as PNG.
When I am executing the program I get a mirror-inverted PNG in Greyscale
that displays all 3 RGB channels seperately from top down and as an
addition these 3 channels are drawn from left to right for 3 times.
I would think I should get a normal RGB PNG as output. What is wrong?
This is the program:
#include "itkRGBPixel.h"
#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkPNGImageIO.h"
#include "itkMetaImageIO.h"
int main(int argc, char ** argv) {
typedef itk::RGBPixel<unsigned char> PixelType;
typedef itk::Image<PixelType, 2> ImageType;
typedef itk::ImageFileReader< ImageType> ReaderType;
typedef itk::ImageFileWriter< ImageType> WriterType;
typedef itk::PNGImageIO WriterImageIOType;
typedef itk::MetaImageIO ReaderImageIOType;
ReaderType::Pointer reader = ReaderType::New();
WriterType::Pointer writer = WriterType::New();
WriterImageIOType::Pointer writerImageIO = WriterImageIOType::New();
ReaderImageIOType::Pointer readerImageIO = ReaderImageIOType::New();
strcpy(input,"a.mhd");
strcpy(output,"a.png");
reader->SetFileName(input);
writer->SetFileName(output);
writerImageIO->SetUseCompression(true);
writerImageIO->SetPixelType(itk::ImageIOBase::IODataType::RGB);
readerImageIO->SetPixelType(itk::ImageIOBase::IODataType::RGB);
writer->SetImageIO(writerImageIO);
reader->SetImageIO(readerImageIO);
writer->SetInput(reader->GetOutput());
try {
writer->Update();
} catch (itk::ExceptionObject &err) {
std::cout<< "Exception caught:" << std::endl;
std::cout<< err <<std::endl;
return -1;
}
return 0;
}
and that is the Content of a.mhd
NDims = 2
DimSize = 2048 1216
ElementSpacing = 0.333 0.333
Position = 0 0
ElementByteOrderMSB = True
ElementNumberOfChannels = 3
ElementType = MET_UCHAR
ElementDataFile = h:\stefan\avf1402b.raw
Thank you for your help
stefan