最近用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'))完美解决
新闻热点
疑难解答