因此,我被要求使用每个像素的加权平均值将BGR图像转换为灰度。你知道吗
img = cv2.imread('..\\Images\\horse.jpg',-1)
height = img.shape[0]
width = img.shape[1]
gray = img.copy()
for x in range(img.shape[1]):
for y in range(img.shape[0]):
gray[y][x]= (0.11 * img[y][x][0] + 0.6 * img[y][x][1] + 0.3 * img[y][x][2])
print(gray)
print(gray.shape)
cv2.imshow('gray',gray)
cv2.waitkey(0)
合成图像的形状:
(404, 640, 3)
它应该是单通道图像,对吗? 结果显示的图像是灰度的,但它仍然是一个3通道的图像,有人能帮我吗?你知道吗
原因很简单,这是因为您在开头复制了整个
img
,它有三个通道。您只需复制一个频道,如下所示:相关问题 更多 >
编程相关推荐