您的位置:首页 > 编程语言 > Python开发

python读取图像时遇到的奇怪问题

2017-02-21 00:32 471 查看
最近用python载入自己的图像数据时,遇到了一个奇怪的问题。

我的程序如下,想要把一张图片载入到data中:

from PIL import Image
from scipy.misc import imread, imresize

data = np.zeros((10,278,278,3))
img = Image.open('kitten.JPEG')
arr = np.array(img)
arr = imresize(arr, (278, 278))
data[0,:,:,:] = arr

plt.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'))


完美解决
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python 图片 数据