File size: 1,266 Bytes
d899b9f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
import warnings
warnings.simplefilter(action='ignore', category=FutureWarning)
import numpy as np
np.bool = np.bool_
import imgaug.augmenters as iaa
from PIL import Image
# Define our sequence of augmentation steps that will be applied to every image.
seq = iaa.Sequential(
[
# Execute one of the following noise augmentations
iaa.OneOf([
iaa.AdditiveGaussianNoise(
loc=0, scale=(0.0, 0.05*255), per_channel=0.5
),
iaa.AdditiveLaplaceNoise(scale=(0.0, 0.05*255), per_channel=0.5),
iaa.AdditivePoissonNoise(lam=(0.0, 0.05*255), per_channel=0.5)
]),
# Execute one or none of the following blur augmentations
iaa.SomeOf((0, 1), [
iaa.OneOf([
iaa.GaussianBlur((0, 3.0)),
iaa.AverageBlur(k=(2, 7)),
iaa.MedianBlur(k=(3, 11)),
]),
iaa.MotionBlur(k=(3, 36)),
]),
],
# do all of the above augmentations in random order
random_order=True
)
def image_corrupt(image: Image):
image_arr = np.array(image)
image_arr = image_arr[None, ...]
image_arr = seq(images=image_arr)
image = Image.fromarray(image_arr[0])
return image
|