I am trying to centralize an image globally using
# 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()))
Then centralize using
# 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)
I get a warning and then an error
Clipping input data to the valid range for imshow with RGB data ([0..1] for floats or [0..255] for integers).
and then on the plt.imsave
function
ValueError: Floating point image RGB values must be in the 0..1 range.
Can anyone kindly explain what is wrong ?