# Grayscale conversion before applying sobel gradient operator

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?

• 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