-
Matt Harvey authored41d3f8a5
"""
Process an image that we can pass to our networks.
"""
from keras.preprocessing.image import img_to_array, load_img
import numpy as np
def process_image(image, target_shape):
"""Given an image, process it and return the array."""
# Load the image.
h, w, _ = target_shape
image = load_img(image, target_size=(h, w))
# Turn it into numpy, normalize and return.
img_arr = img_to_array(image)
x = (img_arr / 255.).astype(np.float32)
return x