On line 4 to 8: We are importing our required packages to create our code. ImageDataGen = ImageDataGenerator(vertical_flip=True) # python program to demonstrate the vertical flip of the image with the vertical_flip = True argument We will save the below program with the name vertical_flip.py. So let's see the Python code for the Vertical flip data augmentation. So for this, we have to pass the vertical_flip=True argument in the ImageDataGenerator constructor. Vertical flip basically flips both rows and columns vertically. Also Read: Horizontal And Vertical Shift Data Augmentation The above program executed and created nine augmented images. The results show the image of the parrot flips horizontally. Now we are going to run the saved horizontal_flip.py python program as shown in the below screenshot. Line 23 to 33: Then the iterator is called as per the iteration value and we got our transformed images as shown below in the result. Line 21: We have created the iterator to perform the transformation on the batch. Line 19: We have created the object (imageDataGen) for the class ImageDataGenerator and passed the argument horizontal_flip = True. 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 a NumPy array so that we can use that in further image processing. Line 11: We have loaded the image from our local drive and loaded 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.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |