Read a image file as a numpy.ndarray, resize it and return the resized images.
# install dependencies by conda
conda install -c conda-forge imageio
conda install scikit-image
from imageio import imread
from skimage.transform import resize
img = imread(file_path)
img_resized = resize(img, (128, 128))
import matplotlib.pyplot as plt
from scipy.misc import imread, imsave, imresize
%matplotlib inline
def read_image_and_resize(path, size=(128, 128), verbose=False):
"""
Read a image file as a numpy.ndarray, resize it and return the resized images.
"""
img = imread(path)
img_resized = imresize(img, size)
if verbose:
print('Image resized from {} to {}'.format(img.shape, img_resized.shape))
plt.figure()
plt.subplot(1, 2, 1);plt.imshow(img)
plt.subplot(1, 2, 2);plt.imshow(img_resized)
return img_resized
# invoke example
img = read_image_and_resize('datasets/train/cat.0.jpg', verbose=True)