【发布时间】:2020-12-11 18:12:15
【问题描述】:
【问题讨论】:
-
可能与**色彩空间有关**参考this视频。
标签: image opencv image-processing image-manipulation brightness
【问题讨论】:
标签: image opencv image-processing image-manipulation brightness
系数(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]
【讨论】: