-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMyTransformations.py
More file actions
101 lines (68 loc) · 2.29 KB
/
MyTransformations.py
File metadata and controls
101 lines (68 loc) · 2.29 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import random
import numpy as np
class RandomHorizontalFlip(object):
def __init__(self, p=0.5):
super().__init__()
self.p = p
def __call__(self, img):
# THIS FLIPS 0 1 2 to 3 4 5
# 3 4 5 0 1 2
prob = random.random()
if prob < self.p:
return np.flip(img,0)
return img
def __repr__(self):
return self.__class__.__name__ + '(p={})'.format(self.p)
class RandomVerticalFlip(object):
def __init__(self, p=0.5):
super().__init__()
self.p = p
def __call__(self, img):
prob = random.random()
if prob < self.p:
return np.flip(img,1)
return img
def __repr__(self):
return self.__class__.__name__ + '(p={})'.format(self.p)
class RandomHorizontalCoordsFlip(object):
def __init__(self, size, p=0.5):
super().__init__()
self.p = p
self.size = size
def __call__(self, coords):
# THIS FLIPS 0 1 2 to 3 4 5
# 3 4 5 0 1 2
# Assumption Sizes and coords are always given in
# lat lon
# above examples has len(lat) = self.size[0] = 2, len(lon) = self.size[1] = 3
prob = random.random()
if prob < self.p:
# flip all horizontal coords
for unit in range(len(coords)):
coords[unit][:,0] = self.size[0]-1-coords[unit][:,0]
return coords
def __repr__(self):
return self.__class__.__name__ + '(p={})'.format(self.p)
class RandomVerticalCoordsFlip(object):
def __init__(self, size, p=0.5):
super().__init__()
self.p = p
self.size = size
def __call__(self, coords):
prob = random.random()
if prob < self.p:
for unit in range(len(coords)):
coords[unit][:,1] = self.size[1]-1-coords[unit][:,1]
return coords
def __repr__(self):
return self.__class__.__name__ + '(p={})'.format(self.p)
class RandomTranspose(object):
def __init__(self, p=0.5):
super().__init__()
self.p = p
def __call__(self, img):
if random.random() < self.p:
return np.transpose(img)
return img
def __repr__(self):
return self.__class__.__name__ + '(p={})'.format(self.p)