Process an Image dataset
To load the images from the image dataset, the simple method is to use load_data() on the image dataset. We are using mnist dataset which is already available in Keras. It will give in return x_train, y_train, x_test, and y_test. The x_train and y_train will be used to train the model and x_test and y_test will be used for testing purposes. We can reshape all the images inside the dataset using reshape() method, and define what type of images should be like ‘float64’ or ‘float32’.
Python3
from keras.datasets import mnist (X_train, Y_train), (X_test, Y_test) = mnist.load_data() # reshape the image images = X_train.reshape( - 1 , 28 , 28 , 1 ).astype( 'float64' ) print (images.shape) print ( type (images)) print (images.size) |
Output:
We see in the above output, 60000 images in mnist have been reshaped into 28 x 28 size and images are of type numpy n-dimensional array.
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