-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathUncertainties_Imgaug.py
52 lines (41 loc) · 1.35 KB
/
Uncertainties_Imgaug.py
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
46
47
48
49
50
import os
import re
import glob
import numpy as np
import torch
from torchvision import datasets, transforms
import matplotlib.pyplot as plt
from PIL import Image
import imgaug.augmenters as iaa
class AddBlock(object):
def __init__(self, gap, type):
self.gap = gap
self.type = type
def __call__(self, img):
height = img.height
img = img.crop((0, 0, height - self.gap, height))
if self.type == "flip":
crop = img.crop((0, 0, self.gap, height))
crop = crop.transpose(Image.FLIP_LEFT_RIGHT)
else:
crop = Image.new("RGB", (self.gap, height), self.type)
joint = Image.new("RGB", (height, height))
joint.paste(crop, (0, 0, self.gap, height))
joint.paste(img, (self.gap, 0, height, height))
return joint
class Weather(object):
def __init__(self, type):
if type == "snow":
self.seq = iaa.imgcorruptlike.Snow(severity=2)
elif type == "rain":
self.seq = iaa.Rain()
elif type == "fog":
self.seq = iaa.Fog()
def __call__(self, img):
width = img.width
height = img.height
img = np.array(img).reshape(1, width, height, 3)
img = self.seq.augment_images(img)
img = np.array(img).reshape(width, height, 3)
img = Image.fromarray(img)
return img