opencvimage-processinggrayscalebgr

Open CV: How does the BGR2GRAY function work?


can anybody explain the mathematical background and function for conversion of BGR2GRAY?

Under https://docs.opencv.org/3.4/de/d25/imgproc_color_conversions.html I found the following for RGB to Gray:

RGB[A] to Gray:Y←0.299⋅R+0.587⋅G+0.114⋅B

Is it the same reversed for BGR? Is it really that simple or is there a more complex method behind:

gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

Solution

  • Since the human vision does not receipt all colors equally, the contributions of the primary colors vary. This depends on the wavelengths of the colors. In the following document on page 7 you can find the formula and also some more explanations: http://poynton.ca/PDFs/ColorFAQ.pdf

    BGR has been used for OpenCV since back then when it was established a couple companies used BGR instead of RGB. The standard is nowadays RGB. Nontheless, the formula for the transformation is equivalent to Y=0.299*R + 0.587*G + 0.114*B