<DIV>Hi Chris,</DIV> <DIV> </DIV> <DIV>I guess you are not correct</DIV> <DIV>I've compared the values obatined by 2 ways:</DIV> <DIV> </DIV> <DIV>1) typedef double PixelType;</DIV> <DIV> </DIV> <DIV>2) typedef itk::RGBPixel<double> PixelType;</DIV> <DIV>---- </DIV> <DIV> </DIV> <DIV>typedef itk::Image<PixelType, 2> ImageType;</DIV> <DIV> </DIV> <DIV>With these 2 cases I read color image from file and get pixel values.</DIV> <DIV>In case 2 I did such conversion (as you told)</DIV> <DIV>pixelvalue = sqrt(pixel.GetRed()*pixel.GetRed() + pixel.GetGreen()*pixel.GetGreen() + pixel.GetBlue()*pixel.GetBlue());</DIV> <DIV> </DIV> <DIV>and compare it with pixel value which I get from case 1, i.e. <FONT size=2>pixelvalue = image->GetPixel(index);</FONT></DIV> <DIV>these two values are differ!</DIV> <DIV>So I looked to the code of ConvertPixelBuffer class and found</DIV> <DIV><FONT size=2>
<div>ConvertRGBToGray</div> <div>{</div></FONT></DIV> <DIV><FONT size=2> <div> OutputComponentType val = static_cast<OutputComponentType>( </div> <div> (2125.0 * static_cast<OutputComponentType>(*inputData) +</div> <div> 7154.0 * static_cast<OutputComponentType>(*(inputData+1)) +</div> <div> 0721.0 * static_cast<OutputComponentType>(*(inputData+2))) / 10000.0 );</div></FONT></DIV> <DIV>}</DIV> <DIV><BR>and tried the same thing with this convertion: the values were equal.</DIV> <DIV>However thanks a lot. Everything is clear already.</DIV> <DIV> </DIV> <DIV>Albert</DIV> <DIV> </DIV> <DIV><BR><B><I>Chris Farmer <cfarmer@scitegic.com></I></B> wrote:</DIV> <BLOCKQUOTE class=replbq style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #1010ff 2px solid"><BR>Hi again
Albert,<BR><BR><BR>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:<BR><BR>ComponentType GetScalarValue() const<BR>{<BR>return static_cast<COMPONENTTYPE> (vcl_sqrt(<BR>static_cast<DOUBLE>(this->operator[](0)) * static_cast<DOUBLE>(this->operator[](0)) +<BR>static_cast<DOUBLE>(this->operator[](1)) * static_cast<DOUBLE>(this->operator[](1)) +<BR>static_cast<DOUBLE>(this->operator[](2)) * static_cast<DOUBLE>(this->operator[](2)))); <BR>}<BR><BR>So, it appears to be giving each of the R, G, and B equal weighting.<BR><BR><BR><BR><BR> <BR>-----Original Message-----<BR>From: Albert Chitemyan
[mailto:abbs_c@yahoo.com] <BR>Sent: Wednesday, November 30, 2005 12:08 AM<BR>To: Chris Farmer<BR>Cc: insight-users@itk.org<BR>Subject: RE: [Insight-users] How does ITK covert color image into grayscaleimage?<BR><BR>Hi Chris,<BR> <BR>I didn't mean that.<BR>I mean, I have got code<BR> <BR>typedef itk::Image<UNSIGNED 2 char,> ImageType;<BR>typedef itk::ImageFileReader<IMAGETYPE> ReaderType;<BR>ReaderType::Pointer reader = ReaderType::New();<BR> <BR>reader->SetFileName("d:\\image.bmp");//color image<BR>reader->Update();<BR> <BR>unsigned char* buffer = reader->GetOutput()->GetBufferPointer();<BR> <BR>what does contain buffer? Is its elements RED(or GREEN or BLUE) channel of color image?<BR>As I know it isn't so. In that case how is obtained these values?<BR> <BR> <BR>Albert<BR> <BR> <BR> <BR> <BR><BR><BR>Chris Farmer <CFARMER@SCITEGIC.COM>wrote:<BR><BR><BR>Hi Albert,<BR><BR>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.<BR><BR><BR>Chris<BR><BR><BR><BR><BR> <BR>-----Original Message-----<BR>From: Albert Chitemyan [mailto:abbs_c@yahoo.com] <BR>Sent: Tuesday, November 29, 2005 11:26 PM<BR>To: insight-users@itk.org<BR>! Subject: [Insight-users] How does ITK covert color image into grayscaleimage?<BR><BR>Hi all,<BR> <BR>As far as I know ITK's most classes are dealing with grayscale
images.<BR>How does ImageFileReader read pixel values from color image?. <BR>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).<BR> <BR>Thanks.<BR> <BR>Albert<BR> <BR> <BR><BR>Yahoo! Music Unlimited - Access over 1 million songs. Try it free.<BR>Click here to report this email as spam.<BR><BR><BR>Yahoo! Music Unlimited - Access over 1 million songs. Try it free.<BR></BLOCKQUOTE> <DIV><BR></DIV><BR><BR><p>
                <hr size=1> <a href="http://pa.yahoo.com/*http://us.rd.yahoo.com/evt=37474/*http://promo.yahoo.com/broadband/
">Yahoo! DSL</a> Something to write home about. Just $16.99/mo. or less