opencv批量灰度转换_OpenCV cvtColor()使用哪种灰度转换算法?

When converting an image in OpenCV from color to grayscale, what conversion algorithm is used? I tried to look this up in the source code on GitHub, but I did not have any success.

The lightness method averages the most prominent and least prominent colors:

(max(R, G, B) + min(R, G, B)) / 2.

The average method simply averages the values:

(R + G + B) / 3.

The luminosity method is a more sophisticated version of the average method. It also averages the values, but it forms a weighted average to account for human perception. We’re more sensitive to green than other colors, so green is weighted most heavily.

The formula for luminosity is 0.21 R + 0.72 G + 0.07 B.

解决方案

The color to grayscale algorithm is stated in the cvtColor() documentation. (search for RGB2GRAY).

The formula used is the same as for CCIR 601:

Y = 0.299 R + 0.587 G + 0.114 B

The luminosity formula you gave is for ITU-R Recommendation BT. 709. If you want that you can specify CV_RGB2XYZ (e.g.) in the third parameter to cvtColor() then extract the Y channel.

You can get OpenCV to to do the "lightness" method you described by doing a CV_RGB2HLS conversion then extract the L channel. I don't think that OpenCV has a conversion for the "average" method,

but if you explore the documentation you will see that there are a few other possibilities.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值