Skip to content

Commit

Permalink
Merge pull request #443 from MarieRoald/floating-point-rotation-angle
Browse files Browse the repository at this point in the history
Minor improvements for geometric rotations
  • Loading branch information
kwcckw authored Sep 17, 2024
2 parents 49f34c6 + 9246273 commit d9cd716
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions augraphy/augmentations/geometric.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Geometric(Augmentation):
xn (int) = image width * xn (float and 0.0 - 1.0);
yn (int) = image height * yn (float and 0.0 - 1.0)
:type crop: tuple, optional
:param rotate_range: Pair of ints determining the range from which to sample
:param rotate_range: Pair of ints or floats determining the range from which to sample
the image rotation.
:type rotate_range: tuple, optional
:param randomize: Flag to apply random geometric transformations.
Expand Down Expand Up @@ -118,7 +118,7 @@ def randomize_parameters(self, image):
random.randint(0, int(ysize / 5)),
]
self.padding_value = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
self.padding_typee = random.choice(["fill", "mirror", "duplicate"])
self.padding_type = random.choice(["fill", "mirror", "duplicate"])

def run_crop(self, image, mask, keypoints, bounding_boxes):
"""Crop image based on the input cropping box.
Expand Down Expand Up @@ -597,15 +597,15 @@ def run_rotation(self, image, mask, keypoints, bounding_boxes):

# generate random angle
if (self.rotate_range[0] != 0) | (self.rotate_range[1] != 0):
angle = random.randint(self.rotate_range[0], self.rotate_range[1])
angle = random.uniform(self.rotate_range[0], self.rotate_range[1])
else:
angle = 0
# rotate image
if angle != 0:
ysize, xsize = image.shape[:2]

# rotate image
image = rotate_image_PIL(image, angle, expand=1)
image = rotate_image_PIL(image, angle, expand=1, background_value=self.padding_value)

# rotate mask
if mask is not None:
Expand Down

0 comments on commit d9cd716

Please sign in to comment.