In [1]:
import numpy as np
import os, os.path
from scipy import misc
In [ ]:
# Read input images into numpy array
def read_image(im_name):
im = misc.imread(im_name, flatten=False, mode='RGB')
return im
# Read all image files in a directory and resize them to 32 x 32 pixels
# Chosen interpolation algorithm may affect the result
def read_images(path):
imgs = []
valid_images = [".jpg", ".gif", ".png", ".tga"]
for f in os.listdir(path):
ext = os.path.splitext(f)[1]
if ext.lower() not in valid_images:
continue
im = read_image(os.path.join(path, f))
im = misc.imresize(im, (32, 32))
imgs.append(im)
return np.array(imgs)
In [ ]: