MCPcopy Create free account
hub / github.com/QWTforGithub/T2LDM / rotate

Function rotate

timm/data/auto_augment.py:88–117  ·  view source on GitHub ↗
(img, degrees, **kwargs)

Source from the content-addressed store, hash-verified

86
87
88def rotate(img, degrees, **kwargs):
89 _check_args_tf(kwargs)
90 if _PIL_VER >= (5, 2):
91 return img.rotate(degrees, **kwargs)
92 elif _PIL_VER >= (5, 0):
93 w, h = img.size
94 post_trans = (0, 0)
95 rotn_center = (w / 2.0, h / 2.0)
96 angle = -math.radians(degrees)
97 matrix = [
98 round(math.cos(angle), 15),
99 round(math.sin(angle), 15),
100 0.0,
101 round(-math.sin(angle), 15),
102 round(math.cos(angle), 15),
103 0.0,
104 ]
105
106 def transform(x, y, matrix):
107 (a, b, c, d, e, f) = matrix
108 return a * x + b * y + c, d * x + e * y + f
109
110 matrix[2], matrix[5] = transform(
111 -rotn_center[0] - post_trans[0], -rotn_center[1] - post_trans[1], matrix
112 )
113 matrix[2] += rotn_center[0]
114 matrix[5] += rotn_center[1]
115 return img.transform(img.size, Image.AFFINE, matrix, **kwargs)
116 else:
117 return img.rotate(degrees, resample=kwargs['resample'])
118
119
120def auto_contrast(img, **__):

Callers

nothing calls this directly

Calls 3

_check_args_tfFunction · 0.85
transformFunction · 0.85
transformMethod · 0.80

Tested by

no test coverage detected