1212- RandomSharpen
1313- RandomGaussianBlur
1414- RandomSaltAndPepper
15+ - RandomMirror
16+ - RandomFlip
1517"""
1618
1719
@@ -177,6 +179,11 @@ def __call__(self, image: Image, annotation: typing.Any) -> typing.Tuple[Image,
177179
178180 # perform the actual rotation and return the image
179181 img = cv2 .warpAffine (image .numpy (), M , (nW , nH ), borderValue = borderValue )
182+
183+ if isinstance (annotation , Image ):
184+ annotation_warp = cv2 .warpAffine (annotation .numpy (), M , (nW , nH ), borderValue = (0 , 0 , 0 ))
185+ annotation .update (annotation_warp )
186+
180187 image .update (img )
181188
182189 return image , annotation
@@ -377,4 +384,72 @@ def __call__(self, image: Image, annotation: typing.Any) -> typing.Tuple[Image,
377384
378385 image .update (img )
379386
387+ return image , annotation
388+
389+
390+ class RandomMirror (Augmentor ):
391+ """ Randomly mirror image"""
392+ def __init__ (
393+ self ,
394+ random_chance : float = 0.5 ,
395+ log_level : int = logging .INFO ,
396+ ) -> None :
397+ """ Randomly mirror image
398+
399+ Args:
400+ random_chance (float): Float between 0.0 and 1.0 setting bounds for random probability. Defaults to 0.5.
401+ log_level (int): Log level for the augmentor. Defaults to logging.INFO.
402+ """
403+ super (RandomMirror , self ).__init__ (random_chance , log_level )
404+
405+ @randomness_decorator
406+ def __call__ (self , image : Image , annotation : typing .Any ) -> typing .Tuple [Image , typing .Any ]:
407+ """ Randomly mirror an image
408+
409+ Args:
410+ image (Image): Image to be mirrored
411+ annotation (typing.Any): Annotation to be mirrored
412+
413+ Returns:
414+ image (Image): Mirrored image
415+ annotation (typing.Any): Mirrored annotation if necessary
416+ """
417+ image = image .flip (0 )
418+ if isinstance (annotation , Image ):
419+ annotation = annotation .flip (0 )
420+
421+ return image , annotation
422+
423+
424+ class RandomFlip (Augmentor ):
425+ """ Randomly flip image"""
426+ def __init__ (
427+ self ,
428+ random_chance : float = 0.5 ,
429+ log_level : int = logging .INFO ,
430+ ) -> None :
431+ """ Randomly mirror image
432+
433+ Args:
434+ random_chance (float): Float between 0.0 and 1.0 setting bounds for random probability. Defaults to 0.5.
435+ log_level (int): Log level for the augmentor. Defaults to logging.INFO.
436+ """
437+ super (RandomFlip , self ).__init__ (random_chance , log_level )
438+
439+ @randomness_decorator
440+ def __call__ (self , image : Image , annotation : typing .Any ) -> typing .Tuple [Image , typing .Any ]:
441+ """ Randomly mirror an image
442+
443+ Args:
444+ image (Image): Image to be flipped
445+ annotation (typing.Any): Annotation to be flipped
446+
447+ Returns:
448+ image (Image): Flipped image
449+ annotation (typing.Any): Flipped annotation if necessary
450+ """
451+ image = image .flip (1 )
452+ if isinstance (annotation , Image ):
453+ annotation = annotation .flip (1 )
454+
380455 return image , annotation
0 commit comments