Applying these transformations to the input image will not change the actual class label of the image data.īut each transformed image will be treated as a new image that the training model has not seen before, so in this way, we are doing another type of regularization technique that works on the training datasets. And the augmentation object picks any value from 0 to maximum(which we defined). So the maximum value which we define in the rotation_range will be the highest range for the random degree value used for rotation. From the results, we can conclude that the rotation works randomly because every time a slightly different image rotation is generated. Now, we have studied another augmentation argument which is rotation, and seen the results. From the output, we can see that the input image rotates from 0 to 90 degrees randomly as a value picked by the augmentation randomly.
Line 22 to 32: Then the iterator is called as per the iteration value and we got our transformed images as shown below in the result.Īlso Read: Random Zoom Image AugmentationĪfter executing the above python code we got the below output as we desire. Line 20: We then created the iterator to perform the transformation on the batch. Line 18: We have then created the object ( imageDataGen) for the class ImageDataGenerator and pass the argument rotation_range = 90.
Line 16: We have then expanded our NumPy array to axis = 0 which means column side. Line 13: In this line, we converting the PIL image format to NumPy array so that we can use that it in further image processing. Line 11: We have loaded the image from our local drive in the 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(rotation_range=90) # 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 rotation shift of the image with the rotation_range argumentįrom import load_imgįrom import img_to_arrayįrom import ImageDataGenerator
If your image is at another location then specify the full path to the load_img(/path/of/the/image) function. Because then only it will read the image. To run this program we have to keep the image (any image) in the same folder where you will keep this python file. Random Rotation Augmentation Python Implementation The example which we have implemented below is for the random rotation because the augmentation will pick any value of the degree from the range 0 to 90 as we specified the maximum degree is 90. The code example below shows the rotation of the image from 0 to 90 degrees using the rotation_range argument.
The rotation_range argument accepts an integer value between 0 to 360. To use this argument in the ImageDataGenerator class constructor, we have to pass the argument rotation_range.
In this method, the pixels of the image rotates. In this method of augmentation, we can rotate the image by 0 to 360 degrees clockwise. From the name of the argument itself, it's clear that we are going to rotate the image to a particular angle.Ĭode: The code of this blog, can be downloaded from the following GitHub link: Random Rotation Augmentation Now, we are going to explain another method for image data augmentation which is called Rotation. In the previous blogs, we studied vertical and horizontal flip image augmentation.