最近用python載入自己的圖像數據時,遇到了一個奇怪的問題。 我的程序如下,想要把一張圖片載入到data中:
from PIL import Imagefrom scipy.misc import imread, imresizedata = np.zeros((10,278,278,3))img = Image.open('kitten.JPEG')arr = np.array(img)arr = imresize(arr, (278, 278))data[0,:,:,:] = arrplt.subplot(1,2,1)plt.imshow(arr)plt.subplot(1,2,2)plt.imshow(data[0,:,:,:])結果在顯示結果時,圖片莫名其妙變成了下圖所示 弄了好久,查了imshow的手冊,終于搞明白了
If your grayscale image is single or double, the default display range is [0 1]. If your image’s data range is much larger or smaller than the default display range, you may need to experiment with setting the display range to see features in the image that would not be visible using the default display range. For all grayscale images having integer types, the default display range is [intmin(class(I)) intmax(class(I))].
搞了半天原來是imshow搞鬼
plt.imshow(data[0,:,:,:].astype('uint8'))完美解決
新聞熱點
疑難解答