From 0a5846d83792be25a10aa4120b0a798a59334adb Mon Sep 17 00:00:00 2001 From: Abhijit Kumar Date: Sun, 28 May 2023 07:22:01 +0530 Subject: [PATCH] Fixed the sign of the angle in image.rotate() method The image.rotate() method used in Operations.py was using a positive angle for performing clockwise rotation and a negative angle for anticlockwise rotation, which was opposite with the behavior of the image.rotate() function that is when this function is given positive angle of rotation then it rotates in anticlockwise direction and for negative angle of rotation it rotates in clockwise direction. This commit corrects the sign of the angle of rotation provided inside the image.rotate() method to ensure the rotation is performed correctly according to the desired clockwise and anticlockwise directions. --- Augmentor/Operations.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/Augmentor/Operations.py b/Augmentor/Operations.py index 4033409..efd6734 100644 --- a/Augmentor/Operations.py +++ b/Augmentor/Operations.py @@ -666,7 +666,10 @@ def perform_operation(self, images): rotation = random_right def do(image): - return image.rotate(rotation, expand=self.expand, resample=Image.BICUBIC, fillcolor=self.fillcolor) + # By default, the image.rotate() method rotates the image in the anticlockwise direction for a positive rotation angle. + # To rotate the image in the clockwise direction, provide a negative rotation angle. + # return image.rotate(rotation, expand=self.expand, resample=Image.BICUBIC, fillcolor=self.fillcolor) + return image.rotate(-rotation, expand=self.expand, resample=Image.BICUBIC, fillcolor=self.fillcolor) augmented_images = [] @@ -723,9 +726,15 @@ def perform_operation(self, images): def do(image): if self.rotation == -1: - return image.rotate(90 * random_factor, expand=True) + # By default, the image.rotate() method rotates the image in the anticlockwise direction for a positive rotation angle. + # To rotate the image in the clockwise direction, provide a negative rotation angle. + # return image.rotate(90 * random_factor, expand=True) + return image.rotate(-1*90 * random_factor, expand=True) else: - return image.rotate(self.rotation, expand=True) + # By default, the image.rotate() method rotates the image in the anticlockwise direction for a positive rotation angle. + # To rotate the image in the clockwise direction, provide a negative rotation angle. + # return image.rotate(self.rotation, expand=True) + return image.rotate(-self.rotation, expand=True) augmented_images = [] @@ -812,8 +821,11 @@ def do(image): x = image.size[0] y = image.size[1] + # By default, the image.rotate() method rotates the image in the anticlockwise direction for a positive rotation angle. + # To rotate the image in the clockwise direction, provide a negative rotation angle. # Rotate, while expanding the canvas size - image = image.rotate(rotation, expand=True, resample=Image.BICUBIC) + # image = image.rotate(rotation, expand=True, resample=Image.BICUBIC) + image = image.rotate(-rotation, expand=True, resample=Image.BICUBIC) # Get size after rotation, which includes the empty space X = image.size[0]