Signal Processing Stack Exchange is a question and answer site for practitioners of the art and science of signal, image and video processing. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am currently replacing a hand-made image processing library by OpenCV. The programmer who worked on this library had implemented the sobel gradient function. This implementation is right except that he first converts his image to grayscale with the formula thereafter (the arithmetic mean):

Y = 0.333 * R + 0.333 * G + 0.333 * B

In OpenCV, I see that they use the formula:

Y = 0.299 * R + 0.587 * G + 0.114 * B

To convert an image to grayscale.

Is the hand-made implementation wrong or can it be motivated by some purpose. Should I always use the OpenCV conversion version?

share|improve this question
If the objects you are imaging have a restricted colour palette, you can adjust the coefficients to give you better contrast. – geometrikal Jun 26 '14 at 0:54

The values used by OpenCV are values used by Luma coding in video systems. Your original code just used an equal weight for each channel.

This may or may not be important for your application (probably not really).

share|improve this answer

The correct way to compute the luminance depends on how the color primaries (red, green blues) were defined when capturing the image.

The coefficients in OpenCV are taken from the CCIR 601 recommendation (and there are other similar standards).

The arithmetic average is more a Q&D approach.

As @Adi said, the nuance is probably qualitatively unimportant for you, except if you need identical reproduction of the results.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.