Line 16: We have expanded our NumPy array to axis = 0 which means column side. Line 13: In this line, we have converted the PIL image format to NumPy array so that we can use that in further image processing. Line 11: We have loaded the image from our local drive and load it with the name variable image. Line 4 to 8: We are importing our required packages to create our code.
# again we convert back to the unsigned integers value of the image for viewing # below we generate augmented images and plotting for visualization Iterator = imageDataGen.flow(imageNew, batch_size=1) # because as we alreay load image into the memory, so we are using flow() function, to apply transformation
ImageDataGen = ImageDataGenerator(horizontal_flip=True) # now here below we creating the object of the data augmentation class # we converting the image which is in PIL format into the numpy array, so that we can apply deep learning methods # python program to demonstrate the horizontal flip of the image with the horizontal_flip = True argumentįrom import load_imgįrom import img_to_arrayįrom import ImageDataGenerator We save the below program with the name horizontal_flip.py.
So let's see python code for the horizontal_flip data augmentation. So for this, we have to pass the horizontal_flip=True argument in the ImageDataGenerator constructor. Horizontal flip basically flips both rows and columns horizontally. Below we have the python code for both the methods with results. We will use the horizontal_flip or vertical_flip arguments to use this technique inside of the ImageDataGenerator class. The vertical and horizontal flip augmentation means they will reverse the pixels rows or column-wise respectively. In this blog, we are going to study one more data augmentation argument which is called Horizontal and Vertical flip augmentation.Ĭode: The code of this blog, can be downloaded from the below GitHub link.