1010- RandomRotate
1111- RandomErodeDilate
1212- RandomSharpen
13+ - RandomGaussianBlur
1314"""
1415
1516def randomness_decorator (func ):
@@ -92,7 +93,7 @@ def __call__(self, image: Image, annotation: typing.Any) -> typing.Tuple[Image,
9293
9394 Returns:
9495 image (Image): Adjusted image
95- annotation (typing.Any): Adjusted annotation
96+ annotation (typing.Any): Adjusted annotation if necessary
9697 """
9798 value = 1 + np .random .uniform (- self ._delta , self ._delta ) / 255
9899
@@ -202,10 +203,12 @@ def __call__(self, image: Image, annotation: typing.Any) -> typing.Tuple[Image,
202203 """ Randomly erode and dilate image
203204
204205 Args:
205- image (np.ndarray): Image to be eroded and dilated
206+ image (Image): Image to be eroded and dilated
207+ annotation (typing.Any): Annotation to be adjusted
206208
207209 Returns:
208- image (np.ndarray): Eroded and dilated image
210+ image (Image): Eroded and dilated image
211+ annotation (typing.Any): Adjusted annotation if necessary
209212 """
210213 kernel = np .ones (self ._kernel_size , np .uint8 )
211214
@@ -218,6 +221,7 @@ def __call__(self, image: Image, annotation: typing.Any) -> typing.Tuple[Image,
218221
219222 return image , annotation
220223
224+
221225class RandomSharpen (Augmentor ):
222226 """ Randomly sharpen image"""
223227 def __init__ (
@@ -255,12 +259,12 @@ def __call__(self, image: Image, annotation: typing.Any) -> typing.Tuple[Image,
255259 """ Randomly sharpen image
256260
257261 Args:
258- image (np.ndarray ): Image to be sharpened
259- annotation (typing.Any): Annotation to be sharpened
262+ image (Image ): Image to be sharpened
263+ annotation (typing.Any): Annotation to be adjusted
260264
261265 Returns:
262- image (np.ndarray ): Sharpened image
263- annotation (typing.Any): Sharpened annotation
266+ image (Image ): Sharpened image
267+ annotation (typing.Any): Adjusted annotation if necessary
264268 """
265269 lightness = np .random .uniform (* self ._ligtness_range )
266270 alpha = np .random .uniform (* self ._alpha_range )
@@ -278,4 +282,41 @@ def __call__(self, image: Image, annotation: typing.Any) -> typing.Tuple[Image,
278282 # Merge the sharpened channels back into the original image
279283 image .update (cv2 .merge ([r_sharp , g_sharp , b_sharp ]))
280284
285+ return image , annotation
286+
287+
288+ class RandomGaussianBlur (Augmentor ):
289+ """ Randomly erode and dilate image"""
290+ def __init__ (
291+ self ,
292+ random_chance : float = 0.5 ,
293+ log_level : int = logging .INFO ,
294+ sigma : typing .Union [int , float ] = 0.5 ,
295+ ) -> None :
296+ """ Randomly erode and dilate image
297+
298+ Args:
299+ random_chance (float): Float between 0.0 and 1.0 setting bounds for random probability. Defaults to 0.5.
300+ log_level (int): Log level for the augmentor. Defaults to logging.INFO.
301+ sigma (int, float): standard deviation of the Gaussian kernel
302+ """
303+ super (RandomGaussianBlur , self ).__init__ (random_chance , log_level )
304+ self .sigma = sigma
305+
306+ @randomness_decorator
307+ def __call__ (self , image : Image , annotation : typing .Any ) -> typing .Tuple [Image , typing .Any ]:
308+ """ Randomly blurs an image with a Gaussian filter
309+
310+ Args:
311+ image (Image): Image to be blurred
312+ annotation (typing.Any): Annotation to be blurred
313+
314+ Returns:
315+ image (Image): Blurred image
316+ annotation (typing.Any): Blurred annotation if necessary
317+ """
318+ img = cv2 .GaussianBlur (image .numpy (), (0 , 0 ), self .sigma )
319+
320+ image .update (img )
321+
281322 return image , annotation
0 commit comments