Ask Your Question

How does opencv convert a bgr image to greyscale?

asked 2016-02-04 05:15:56 -0500

RVQ gravatar image


I have a simple question. I read about the cvtColor function in the docs. I would like to know how OpenCV converts a BGR image to greyscale image.

According to the docs it uses the following formular.


Is it correct, that the Y stands for the alpha channel and all values in this channel will be replaced by 0.299?

Thanks in advance!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2016-02-04 05:39:55 -0500

berak gravatar image

updated 2016-02-04 05:40:52 -0500

the Y stands for the grayscale pixel value, not for alpha (which is irrelevant for computer vision, and thus just gets discarded)

the formula is actually a weighted sum,

gray = (0.299 * red) + (0.587 * green) + (0.114 * blue).

maybe it gets more obvious, if you just add up the factors:

0.299 + 0.587 + 0.114 = 1

edit flag offensive delete link more


Thank you for clarification!

RVQ gravatar imageRVQ ( 2016-02-04 06:01:05 -0500 )edit

Question Tools

1 follower


Asked: 2016-02-04 05:15:56 -0500

Seen: 248 times

Last updated: Feb 04 '16