FW: [Insight-users] How does ITK covert color image into grayscaleimage?

Chris Farmer cfarmer at scitegic.com
Wed Nov 30 03:52:00 EST 2005


Hi again Albert,


It looks like all that logic is inside the ConvertPixelBuffer class which takes a ConvertPixelTraits template argument.  You could override the current conversion behavior and supply your own rules by specifying a custom ConvertPixelTraits type into your file reader.  That said, the default implementation calls into the GetScalarValue() method of the PixelType.  If your type is RGBPixel, then this is the conversion:

  ComponentType GetScalarValue() const
    {
      return static_cast<ComponentType> (vcl_sqrt(
        static_cast<double>(this->operator[](0)) * static_cast<double>(this->operator[](0)) +
        static_cast<double>(this->operator[](1)) * static_cast<double>(this->operator[](1)) +
        static_cast<double>(this->operator[](2)) * static_cast<double>(this->operator[](2)))); 
    }

So, it appears to be giving each of the R, G, and B equal weighting.




 
-----Original Message-----
From: Albert Chitemyan [mailto:abbs_c at yahoo.com] 
Sent: Wednesday, November 30, 2005 12:08 AM
To: Chris Farmer
Cc: insight-users at itk.org
Subject: RE: [Insight-users] How does ITK covert color image into grayscaleimage?

Hi Chris,
 
I didn't mean that.
I mean, I have got code
 
typedef itk::Image<unsigned char, 2> ImageType;
typedef itk::ImageFileReader<ImageType> ReaderType;
ReaderType::Pointer reader = ReaderType::New();
 
reader->SetFileName("d:\\image.bmp");//color image
reader->Update();
 
unsigned char* buffer = reader->GetOutput()->GetBufferPointer();
 
what does contain buffer? Is its elements RED(or GREEN or BLUE) channel of color image?
As I know it isn't so. In that case how is obtained these values?
 
 
Albert
 
 
 
 


Chris Farmer <cfarmer at scitegic.com> wrote:


Hi Albert,

Check out the itk::RGBPixel type. If you use RGBPixel as the template type of your itk::Image, then you'll get access to the R, G, and B channels in your image. There are some good sections on this early in the ITK software guide. You're right that many ITK operations are not available to RGB images. You could flatten your images to a scalar pixel type with the RGBToLuminanceImageFilter or treat it as a vector image with the RGBToVectorImageAdaptor. There are at least a few messages in the very recent past from the list that mention these classes, and there are some examples in the ITK source distribution that show how you can work with RGB images.


Chris




 
-----Original Message-----
From: Albert Chitemyan [mailto:abbs_c at yahoo.com] 
Sent: Tuesday, November 29, 2005 11:26 PM
To: insight-users at itk.org
! Subject: [Insight-users] How does ITK covert color image into grayscaleimage?

Hi all,
 
As far as I know ITK's most classes are dealing with grayscale images.
How does ImageFileReader read pixel values from color image?. 
Does it take only one component(e.g. red) of RGB, or copmute pixel value using those 3 components?(grayscale pixel value = R*a + G*b + B*c).
 
Thanks.
 
Albert
 
 

Yahoo! Music Unlimited - Access over 1 million songs. Try it free.
Click here to report this email as spam.


Yahoo! Music Unlimited - Access over 1 million songs. Try it free.


More information about the Insight-users mailing list