Intel® Integrated Performance Primitives
Deliberate problems developing high-performance vision, signal, security, and storage applications.

## RGBToGray Beginner
378 Views

I'm a little confused. The function RGBToGray will work for BGR format too? Or I have to do the conversion before? Thank you very much.

6 Replies Beginner
378 Views

If there's a version with planar input, then yes you could and just swap the R and B planes Beginner
378 Views
I don't understand ... A tell about calc... I can't use BGR24 directly? First I need swap or IPP will work with BGR24 too? T don't know how IPP convert to gray. Thanks. Beginner
378 Views
Thank you very much! So, here worked fine with BGR format too =] Valued Contributor II
378 Views
Please use full names for IPP functions when you're describing a problem or asking a question. Thanks in advance. Note: Actually this is a discussion about a set of IPP functions ippiRGBToGray_xx_xxxxx. >>... So, here worked fine with BGR format too... A very famous equation Y = 0.299 * R + 0.587 * G + 0.114 * B is used to do this conversion RGB to Gray. However, you need to verify that it doesn't do something like: Y = 0.299 * B + 0.587 * G + 0.114 * R I'm Not sure that it does not. Employee
378 Views

If Sergey are right and you see wrong coefficients for B & R - use another function, please:

/* /////////////////////////////////////////////////////////////////////////////
//  Name:       ippiColorToGray
//  Purpose:    Converts an RGB image to gray scale (custom coefficients)
//  Parameters:
//     pSrc      Pointer to the source image , points to point(0,0)
//     pDst      Pointer to the destination image , points to point(0,0)
//     roiSize   Size of the ROI in pixels. Since the function performs point
//               operations (without a border), the ROI may be the whole image.
//     srcStep   Step in bytes through the source image to jump on the next line
//     dstStep   Step in bytes through the destination image to jump on the next line
//     coeffs User-defined vector of coefficients.
//                 The sum of the coefficients should be less than or equal to 1
//  Returns:
//           ippStsNullPtrErr  pSrc == NULL, or pDst == NULL
//           ippStsSizeErr     roiSize has a field with zero or negative value
//           ippStsNoErr       No errors
//
//  The following equation is used to convert an RGB image to gray scale:
//
//   Y = coeffs * R + coeffs * G + coeffs * B;
//
//
*/

just swap coefficients from the formula above.

Regards, Igor Valued Contributor II
378 Views
This is a short follow up with some technical details. >>A very famous equation >> >>Y = 0.299 * R + 0.587 * G + 0.114 * B >> >>is used to do this conversion RGB to Grey. However, you need to verify that it doesn't do something like: >> >>Y = 0.299 * B + 0.587 * G + 0.114 * R Let's say R=64, G=128, B=192, then Case 1 Y = 0.299 * R + 0.587 * G + 0.114 * B Y = 0.299 * 64 + 0.587 * 128 + 0.114 * 192 = 116.16 Case 2 Y = 0.299 * B + 0.587 * G + 0.114 * R Y = 0.299 * 192 + 0.587 * 128 + 0.114 * 64 = 139.84 Intensity of a grey image is Not the same, as you can see. In some applications, like X-Ray imaging or MRI, incorect conversions are Not allowed. 