答案 0 :(得分:1)
系数(0.241,0.691,0.068)用于计算luminance
例如:
如果您有彩色(RGB)图像并且想要转换为灰度:
ITU-BT709建议使用这些系数,它们是HDTV的标准。
因此,为了计算亮度,可接受的系数为0.241、0.691和0.068。
您可以打印亮度值:
import cv2
import numpy as np
# img will be BGR image
img = cv2.imread("samurgut3.jpeg")
#When we square the values overflow will occur if we have uint8 type
img = np.float64(img)
# Extract each channel
Cr = img[:, :, 2]
Cg = img[:, :, 1]
Cb = img[:, :, 0]
# Get width and height
Width = img.shape[0]
Height = img.shape[1]
#I don't think so about the height and width will not be here
brightness = np.sqrt((0.241 * (Cr**2)) + (0.691 * (Cg**2)) + (0.068 * (Cb**2))) / (Width * Height)
#We convert float64 to uint8
brightness =np.uint8(np.absolute(brightness))
print(brightness)
输出:
[[4.42336257e-05 4.09825832e-05 4.09825832e-05 ... 3.44907525e-05
4.13226678e-05 4.13226678e-05]
[4.09825832e-05 4.09825832e-05 4.09825832e-05 ... 3.44907525e-05
4.13226678e-05 4.13226678e-05]