因此,我编写了这段小代码,尝试将RGBimge转换为Grayscale从该已接受答案中获取的代码。问题是,即使我只是重新创建原始图像,它也显示出与原始图像不相似的神秘图像。您认为问题是什么,我们应该如何解决呢?另外,我想将其转换Grayscale为给定的数组b。这是我的代码:import matplotlib.image as imgimport matplotlib.pyplot as pltfrom PIL import Imageimport numpy as npa = img.imread('hCeFA.png')a = a * 255 #Matplotlib gives float values between 0-1b = a * np.array([0.3, 0.59, 0.11])b = np.sum(b, axis = 2) / 3 #Grayscale conversionimg1 = Image.fromarray(a, 'RGB')img1.save('my.png')img1.show() #Gives a cryptic imageplt.imshow(a/255, interpolation='nearest') #Works fineplt.show()
1 回答

跃然一笑
TA贡献1826条经验 获得超6个赞
更好地使用“ I”读取图像。像 imread('imageName.imgFormat',"I")
这将解决这个问题。它会以uint8格式读取图像,我想您会这样。
添加回答
举报
0/150
提交
取消