【发布时间】:2020-01-21 13:23:47
【问题描述】:
我想制作一个程序,将RGB图像大量转换为灰度,我使用这个代码
files = [f for f in listdir(path) if isfile(join(path,f))]
for image in files:
try:
img = cv2.imread(os.path.join(path,image))
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
dstPath = join(dstpath,image)
cv2.imwrite(dstPath,gray)
except:
print ("{} is not converted".format(image))
你们能给我解释一下吗 cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)的工作或算法如何
或者更准确地说,程序代码 sn-p 如何将 RGB 图像转换为灰度图像?怎么计算的?
算法是否对图像中的所有像素使用公式R + G + B / 3,以便将其转换为灰度图像??
【问题讨论】:
-
它在the opencv docs。该公式比 3 个通道的平均值更复杂。
-
在文档中,点符号为“.”在“RGB [A] 到灰色:Y ← 0.299⋅R + 0.587⋅G + 0.114⋅B”中,这是否意味着相乘? “Y”是什么意思?这是灰度符号吗?
-
对你的两个问题都是:Gray = 0.299*R + 0.587*G + 0.114*B
标签: python opencv rgb opencv3.0 grayscale