MCPcopy Create free account
hub / github.com/HobbitLong/PyContrast / __call__

Method __call__

pycontrast/datasets/util.py:55–75  ·  view source on GitHub ↗
(self, img)

Source from the content-addressed store, hash-verified

53 self.angles = angles
54
55 def __call__(self, img):
56 angle = np.random.choice(self.angles)
57 if isinstance(img, Image.Image):
58 img = img.rotate(angle, fillcolor=(128, 128, 128))
59 return img
60 elif isinstance(img, np.ndarray):
61 if angle == 0:
62 pass
63 elif angle == 90:
64 img = np.flipud(np.transpose(img, (1, 0, 2)))
65 elif angle == 180:
66 img = np.fliplr(np.flipud(img))
67 elif angle == 270:
68 img = np.transpose(np.flipud(img), (1, 0, 2))
69 else:
70 img = Image.fromarray(img)
71 img = img.rotate(angle, fillcolor=(128, 128, 128))
72 img = np.asarray(img)
73 return img
74 else:
75 raise TypeError('not supported type in rotation: ', type(img))
76
77
78class RGB2RGB(object):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected