【发布时间】:2021-06-06 00:14:25
【问题描述】:
我必须仅使用 4 行将图像从 rgb 比例转换为灰度图像,在“插入代码部分”中,我可以使用 CV 执行此操作,但我通过计算将彩色图像转换为黑白图像RGB 值的平均值。如果平均值接近 255,则将像素设置为白色 (255),否则设置为黑色 (0)。为了转换为灰度图像,原则上必须将像素值设置为 RGB 值的平均值。我应该为每个 RGB 值使用一个加权因子。
import matplotlib.pyplot
import numpy as np
myImage = matplotlib.pyplot.imread('flower.png')
height=myImage.shape[0]
width=myImage.shape[1]
for x in range(0, height-1):
for y in range(0,width-1):
#insert code
imgplot = matplotlib.pyplot.imshow(myImage)
matplotlib.pyplot.show()
【问题讨论】: