10
10
- RandomRotate
11
11
- RandomErodeDilate
12
12
- RandomSharpen
13
+ - RandomGaussianBlur
13
14
"""
14
15
15
16
def randomness_decorator (func ):
@@ -92,7 +93,7 @@ def __call__(self, image: Image, annotation: typing.Any) -> typing.Tuple[Image,
92
93
93
94
Returns:
94
95
image (Image): Adjusted image
95
- annotation (typing.Any): Adjusted annotation
96
+ annotation (typing.Any): Adjusted annotation if necessary
96
97
"""
97
98
value = 1 + np .random .uniform (- self ._delta , self ._delta ) / 255
98
99
@@ -202,10 +203,12 @@ def __call__(self, image: Image, annotation: typing.Any) -> typing.Tuple[Image,
202
203
""" Randomly erode and dilate image
203
204
204
205
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
206
208
207
209
Returns:
208
- image (np.ndarray): Eroded and dilated image
210
+ image (Image): Eroded and dilated image
211
+ annotation (typing.Any): Adjusted annotation if necessary
209
212
"""
210
213
kernel = np .ones (self ._kernel_size , np .uint8 )
211
214
@@ -218,6 +221,7 @@ def __call__(self, image: Image, annotation: typing.Any) -> typing.Tuple[Image,
218
221
219
222
return image , annotation
220
223
224
+
221
225
class RandomSharpen (Augmentor ):
222
226
""" Randomly sharpen image"""
223
227
def __init__ (
@@ -255,12 +259,12 @@ def __call__(self, image: Image, annotation: typing.Any) -> typing.Tuple[Image,
255
259
""" Randomly sharpen image
256
260
257
261
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
260
264
261
265
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
264
268
"""
265
269
lightness = np .random .uniform (* self ._ligtness_range )
266
270
alpha = np .random .uniform (* self ._alpha_range )
@@ -278,4 +282,41 @@ def __call__(self, image: Image, annotation: typing.Any) -> typing.Tuple[Image,
278
282
# Merge the sharpened channels back into the original image
279
283
image .update (cv2 .merge ([r_sharp , g_sharp , b_sharp ]))
280
284
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
+
281
322
return image , annotation
0 commit comments