[Insight-users] Using ImageReadCastWrite Example

Luis Ibanez luis.ibanez at kitware.com
Mon Jun 28 23:35:25 EDT 2004


Hi Eugine,

If you want the image to be read and written in color
you must use a RGBPixel<> type as the image pixel type.

Please look at the examples:

    Insight/Examples/IO/
               RGBImageReadWrite.cxx
               RGBImageSeriesReadWrite.cxx


Regards,


    Luis


-----------------------
EUGINE NIZKER wrote:

> Hello,
> 
> I have recently downloaded and installed ITK version 1.6 and am trying to use it for doing a GE5 -> PNG conversion.  I gather that the ImageReadCastWrite code contains the proper info for that, and can actually get the image to show, but the problem is that it's in greyscale (almost black and white) instead of being in full color like the original image (seen by MRIcro).  
> 
> I tested this with other conversions like .bmp to .jpg or even .jpg to .jpg and the output always appears black and white for whatever reason...  I am currently using the RescaleIntensityImageFilter between the input and output since this is the one that was used in the example.  Could this be the problem?  I tried changing the maximum and minimum intensity settings on the filter, but that didn't seem to affect the output image at all.  
> 
> Can anyone please help?  
> 
> 
> 
> Here is my code just in case it's helpful:
> 
> /*=========================================================================
> 
>   Program:   Insight Segmentation & Registration Toolkit
>   Module:    $RCSfile: ImageReadCastWrite.cxx,v $
>   Language:  C++
>   Date:      $Date: 2003/12/17 12:55:28 $
>   Version:   $Revision: 1.7 $
> 
>   Copyright (c) Insight Software Consortium. All rights reserved.
>   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
> 
>      This software is distributed WITHOUT ANY WARRANTY; without even 
>      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
>      PURPOSE.  See the above copyright notices for more information.
> 
> =========================================================================*/
> 
> #include "itkImageFileReader.h"
> #include "itkImageFileWriter.h"
> #include "itkRescaleIntensityImageFilter.h"
> 
> #include "itkCropImageFilter.h"
> 
> 
> #include "itkImage.h"
> 
> 
> int main( int argc, char ** argv )
> {
>   if( argc < 3 )
>     {
>     std::cerr << "Usage: " << std::endl;
>     std::cerr << argv[0] << " inputImageFile  outputImageFile " << std::endl;
>     return -1;
>     }
> 
> 
>   typedef unsigned char       InputPixelType;
>   typedef unsigned char       OutputPixelType;
>   const   unsigned int        Dimension = 2;
> 
>   typedef itk::Image< InputPixelType,  Dimension >    InputImageType;
>   typedef itk::Image< OutputPixelType, Dimension >    OutputImageType;
> 
>   typedef itk::ImageFileReader< InputImageType  >  ReaderType;
>   typedef itk::ImageFileWriter< OutputImageType >  WriterType;
> 
> 
>   typedef itk::RescaleIntensityImageFilter< 
>                                   InputImageType, 
>                                   OutputImageType >    FilterType;
>  
>   FilterType::Pointer filter = FilterType::New();
>   filter->SetOutputMinimum(   0 );
>   filter->SetOutputMaximum( 255 );
> 
>   ReaderType::Pointer reader = ReaderType::New();
>   WriterType::Pointer writer = WriterType::New();
> 
>   filter->SetInput( reader->GetOutput() );
>   writer->SetInput( filter->GetOutput() );
> 
> 
>   const char * inputFilename  = argv[1];
>   const char * outputFilename = argv[2];
> 
>   reader->SetFileName( inputFilename  );
>   writer->SetFileName( outputFilename );
> 
> 
>   try 
>     { 
>     writer->Update(); 
>     } 
>   catch( itk::ExceptionObject & err ) 
>     { 
>     std::cout << "ExceptionObject caught !" << std::endl; 
>     std::cout << err << std::endl; 
>     return -1;
>     } 
> 
> 
>   return 0;
> }
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
> 





More information about the Insight-users mailing list