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

Albert Chitemyan abbs_c at yahoo.com
Wed Nov 30 05:47:23 EST 2005


Hi Chris,
   
  I guess you are not correct
  I've compared the values obatined by 2 ways:
   
  1)  typedef double PixelType;
   
  2) typedef itk::RGBPixel<double> PixelType;
  ---- 
   
  typedef itk::Image<PixelType, 2> ImageType;
   
  With these 2 cases I read color image from file and get pixel values.
  In case 2 I did such conversion (as you told)
  pixelvalue = sqrt(pixel.GetRed()*pixel.GetRed() + pixel.GetGreen()*pixel.GetGreen() + pixel.GetBlue()*pixel.GetBlue());
   
  and compare it with pixel value which I get from case 1, i.e. pixelvalue = image->GetPixel(index);
  these two values are differ!
  So I looked to the code of ConvertPixelBuffer class and found
    ConvertRGBToGray
  {

           OutputComponentType val = static_cast<OutputComponentType>( 
         (2125.0 * static_cast<OutputComponentType>(*inputData) +
          7154.0 * static_cast<OutputComponentType>(*(inputData+1)) +
          0721.0 * static_cast<OutputComponentType>(*(inputData+2))) / 10000.0 );

  }
  
and tried the same thing with this convertion: the values were equal.
  However thanks a lot. Everything is clear already.
   
  Albert
   
  
Chris Farmer <cfarmer at scitegic.com> wrote:
  
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 (vcl_sqrt(
static_cast(this->operator[](0)) * static_cast(this->operator[](0)) +
static_cast(this->operator[](1)) * static_cast(this->operator[](1)) +
static_cast(this->operator[](2)) * static_cast(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 ImageType;
typedef itk::ImageFileReader 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 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.
  




		
---------------------------------
 Yahoo! DSL Something to write home about. Just $16.99/mo. or less
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20051130/d2008dc7/attachment.html


More information about the Insight-users mailing list