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

Function rotate

pycontrast/datasets/RandAugment.py:77–106  ·  view source on GitHub ↗
(img, degrees, **kwargs)

Source from the content-addressed store, hash-verified

75
76
77def rotate(img, degrees, **kwargs):
78 _check_args_tf(kwargs)
79 if _PIL_VER >= (5, 2):
80 return img.rotate(degrees, **kwargs)
81 elif _PIL_VER >= (5, 0):
82 w, h = img.size
83 post_trans = (0, 0)
84 rotn_center = (w / 2.0, h / 2.0)
85 angle = -math.radians(degrees)
86 matrix = [
87 round(math.cos(angle), 15),
88 round(math.sin(angle), 15),
89 0.0,
90 round(-math.sin(angle), 15),
91 round(math.cos(angle), 15),
92 0.0,
93 ]
94
95 def transform(x, y, matrix):
96 (a, b, c, d, e, f) = matrix
97 return a * x + b * y + c, d * x + e * y + f
98
99 matrix[2], matrix[5] = transform(
100 -rotn_center[0] - post_trans[0], -rotn_center[1] - post_trans[1], matrix
101 )
102 matrix[2] += rotn_center[0]
103 matrix[5] += rotn_center[1]
104 return img.transform(img.size, Image.AFFINE, matrix, **kwargs)
105 else:
106 return img.rotate(degrees, resample=kwargs['resample'])
107
108
109def auto_contrast(img, **__):

Callers

nothing calls this directly

Calls 2

_check_args_tfFunction · 0.85
transformFunction · 0.85

Tested by

no test coverage detected