pil normalize image
# load image image = Image.open('sydney_bridge.jpg') pixels = asarray(image) # convert from integers to floats pixels = pixels.astype('float32') # normalize to the range 0-1 pixels /= 255.0
Here is what the above code is Doing:
1. The first line loads the image into memory.
2. The second line converts the image into a NumPy array.
3. The third line converts the pixel values from integers to floats, which are
required by the Keras API.
4. The fourth line normalizes the pixel values from the range 0-255 to the range
0-1.