Convert image into an array
There is img_to_array() method to convert images into array, and array_to_img() method to convert image array back to image. In the below example, we are just accessing the 0th index of the image array. We can get information like image array shape, type, etc. When the image array is converted to an image, it again is a PIL object.
Python3
# convert image into array from keras.preprocessing.image import img_to_array from keras.preprocessing.image import array_to_img # convert to numpy array img_array = img_to_array(img) print (img_array[ 0 ]) print (img_array.dtype) print (img_array.shape) # convert back to image img = array_to_img(img_array) print ( type (img)) |
Output:
Image Processing with Keras in Python
In this article, we are doing Image Processing with Keras in Python. Keras API is a deep learning library that provides methods to load, prepare and process images.
We will cover the following points in this article:
- Load an image
- Process an image
- Convert Image into an array and vice-versa
- Change the color of the image
- Process image dataset