[Insight-users] RGB images from Visible Human Dataset

Luis Ibanez luis . ibanez at kitware . com
Thu, 30 Oct 2003 10:14:45 -0500


This is a multi-part message in MIME format.
--------------070303060502010100070707
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit


Hi Stefan,

I tried your code and was able to write a color
PNG from a color MetaImage.  The only modification
needed in the code was on the enum

     itk::ImageIOBase::IODataType::RGB

that should be:

     itk::ImageIOBase::RGB


Please find attched to this email the file I used.


Let us know what kind of platform are you using,
and the version of ITK that you are working with.


Thanks


    Luis


BTW
Note that the MetaImage format expects that the header
file and the raw binary data file will be located in the
same directory. Your header file shouldn't have absolute
paths on it.



----------------------
Stefan Lindenau wrote:
> 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
> 
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk . org
> http://www . itk . org/mailman/listinfo/insight-users
> 

========================================================================



--------------070303060502010100070707
Content-Type: text/plain;
 name="VisibleHuman.cxx"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="VisibleHuman.cxx"


#include "itkRGBPixel.h"
#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkPNGImageIO.h"
#include "itkMetaImageIO.h"
#include "itkImageIOBase.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();

    std::string input  = "image.mhd";
    std::string output = "image.png";

    reader->SetFileName( input.c_str() );
    writer->SetFileName( output.c_str() );
   
    writerImageIO->SetUseCompression(true);
    writerImageIO->SetPixelType(itk::ImageIOBase::RGB);

    readerImageIO->SetPixelType(itk::ImageIOBase::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;
}



--------------070303060502010100070707--