【发布时间】:2020-06-05 00:51:57
【问题描述】:
我正在尝试使用全局集中图像
# example of global centering (subtract mean)
from numpy import asarray
from PIL import Image
# load image
image = Image.open('13.jpg')
pixels = asarray(image)
# convert from integers to floats
pixels = pixels.astype('float32')
# calculate global mean
mean = pixels.mean()
print('Mean: %.3f' % mean)
print('Min: %.3f, Max: %.3f' % (pixels.min(), pixels.max()))
# global centering of pixels
global_pixels = pixels - mean
# confirm it had the desired effect
mean = global_pixels.mean()
print('Mean: %.3f' % mean)
print('Min: %.3f, Max: %.3f' % (global_pixels.min(), global_pixels.max()))
然后使用中心化
# normalize to the range 0-1
pixels_new = global_pixels/ 255.0
# confirm the normalization
print('Min: %.3f, Max: %.3f' % (pixels_new.min(), pixels_new.max()))
plt.imshow(np.array(pixels_new))
plt.imsave('test1.png', pixels_new)
我收到一个警告,然后是一个错误
使用 RGB 数据将输入数据剪切到 imshow 的有效范围 ([0..1] 表示浮点数或 [0..255] 表示整数)。
然后在plt.imsave函数上
ValueError: 浮点图像 RGB 值必须在 0..1 范围内。
谁能解释一下哪里出了问题?
【问题讨论】:
标签: python numpy matplotlib