def load_transform(image_path, angle=0., s=(0, 0), size=(20, 20)):
# Load the image
original = imread(image_path, flatten=True)
# Rotate the image
rotated = np.maximum(np.minimum(rotate(original, angle=angle, cval=1.), 1.), 0.)
# Shift the image
shifted = shift(rotated, shift=s)
# Resize the image
resized = np.asarray(scipy.misc.imresize(rotated, size=size), dtype=theano.config.floatX) / 255.
# Invert the image
inverted = 1. - resized
max_value = np.max(inverted)
if max_value > 0.:
inverted /= max_value
return inverted
评论列表
文章目录