MCPcopy Create free account
hub / github.com/MaureenZOU/TSAM / GroupRandomCrop

Class GroupRandomCrop

src/data_loader/transform.py:13–37  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11
12
13class GroupRandomCrop(object):
14 def __init__(self, size):
15 if isinstance(size, numbers.Number):
16 self.size = (int(size), int(size))
17 else:
18 self.size = size
19
20 def __call__(self, img_group):
21
22 w, h = img_group[0].size
23 th, tw = self.size
24
25 out_images = list()
26
27 x1 = random.randint(0, w - tw)
28 y1 = random.randint(0, h - th)
29
30 for img in img_group:
31 assert(img.size[0] == w and img.size[1] == h)
32 if w == tw and h == th:
33 out_images.append(img)
34 else:
35 out_images.append(img.crop((x1, y1, x1 + tw, y1 + th)))
36
37 return out_images
38
39
40class GroupCenterCrop(object):

Callers 2

__call__Method · 0.70
transform.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected