[Insight-users] problem with RGB .bmp images
John
dbgtjp at hotmail.com
Wed Oct 1 06:15:01 EDT 2008
Luis Ibanez <luis.ibanez at ...> writes:
>
>
> Hi John,
>
> Are you declaring your image as an image whose
> pixel type is itkRGBPixel<> ?
>
> Please provide a minimal code snippet illustrating your problem.
>
> Thanks
>
> Luis
Hi Luis,
Of course I declared the pixel type as itk::RGBPixel.
To verify that it is not an error of my code I took the example from
Examples/DataRepresentation/Image/RGBImage.cxx.
The following code results for the image http://jperl.gu6.info/000.bmp
in the output:
Pixel values from GetRed,GetGreen,GetBlue:
Red = 137
Green = 137
Blue = 137
Pixel values:
Red = 137
Green = 137
Blue = 137
Here the code I used:
#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkRGBPixel.h"
int main( int , char * argv[] )
{
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] );
reader->Update();
ImageType::Pointer image = reader->GetOutput();
ImageType::IndexType pixelIndex;
pixelIndex[0] = 90;
pixelIndex[1] = 435;
PixelType onePixel = image->GetPixel( pixelIndex );
PixelType::ValueType red = onePixel.GetRed();
PixelType::ValueType green = onePixel.GetGreen();
PixelType::ValueType blue = onePixel.GetBlue();
std::cout << "Pixel values from GetRed,GetGreen,GetBlue:"
<< std::endl;
std::cout << "Red = "
<< itk::NumericTraits<PixelType::ValueType>::PrintType(red)
<< std::endl;
std::cout << "Green = "
<< itk::NumericTraits<PixelType::ValueType>::PrintType(green)
<< std::endl;
std::cout << "Blue = "
<< itk::NumericTraits<PixelType::ValueType>::PrintType(blue)
<< std::endl;
red = onePixel[0]; // extract Red component
green = onePixel[1]; // extract Green component
blue = onePixel[2]; // extract Blue component
std::cout << "Pixel values:" << std::endl;
std::cout << "Red = "
<< itk::NumericTraits<PixelType::ValueType>::PrintType(red)
<< std::endl;
std::cout << "Green = "
<< itk::NumericTraits<PixelType::ValueType>::PrintType(green)
<< std::endl;
std::cout << "Blue = "
<< itk::NumericTraits<PixelType::ValueType>::PrintType(blue)
<< std::endl;
return 0;
}
I tried the above code on linux and windows with the same result.
Hope this helps you.
John
More information about the Insight-users
mailing list