I'm trying to resize some images that I've loaded using matplotlib's imread function. An example:
plt.figure()
plt.imshow(imgs[0])
plt.colorbar()
plt.grid(False)
plt.show()
However, when I try to apply the resize function and then replot:
def rescale_image(img):
"""Rescale the jpg range of 0-255 to 0-1"""
img = resize(img, (100, 100), anti_aliasing=True)
return img /255
#imgs = [rescale_image(i) for i in imgs]
io = rescale_image(imgs[0])
plt.figure()
plt.imshow(io)
plt.colorbar()
plt.grid(False)
plt.show()
Why?
UPDATE: The import statements:
%matplotlib inline
import matplotlib.pyplot as plt
from matplotlib.image import imread
from skimage.transform import resize
imgs = [imread(p) for p in paths_list]# paths list is generated by glob.glob on the folder of images
Your image starts out with pixels in the range 0..1. When you resize it, you divide by 255, so the range is now 0..0.003 so it looks black.
Solution?
Change this line:
return img /255
to this:
return img