因此,我編寫了這段小代碼,嘗試將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
提交
取消