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

Class GroupRandomCrop

src/data_loader/transform_flow.py:14–41  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12from utils.visual_helper import resize_flow_np
13
14class GroupRandomCrop(object):
15 def __init__(self, size):
16 if isinstance(size, numbers.Number):
17 self.size = (int(size), int(size))
18 else:
19 self.size = size
20
21 def __call__(self, img_dict):
22 w, h = img_dict['gt_frames'][0].size
23 th, tw = self.size
24
25 # out_images = list()
26 x1 = random.randint(0, w - tw)
27 y1 = random.randint(0, h - th)
28
29 img_dict['gt_frames'] = [img.crop((x1, y1, x1+tw, y1+th)) for img in img_dict['gt_frames']]
30 img_dict['flow_forward'] = [img[y1:y1+th, x1:x1+tw, :] for img in img_dict['flow_forward']]
31 img_dict['flow_backward'] = [img[y1:y1+th, x1:x1+tw, :] for img in img_dict['flow_backward']]
32 img_dict['flowmask_forward'] = [img.crop((x1, y1, x1+tw, y1+th)) for img in img_dict['flowmask_forward']]
33 img_dict['flowmask_backward'] = [img.crop((x1, y1, x1+tw, y1+th)) for img in img_dict['flowmask_backward']]
34
35 # for img in img_group:
36 # assert(img.size[0] == w and img.size[1] == h)
37 # if w == tw and h == th:
38 # out_images.append(img)
39 # else:
40 # out_images.append(img.crop((x1, y1, x1 + tw, y1 + th)))
41 return img_dict
42
43
44class GroupToFlow(object):

Callers 5

__init__Method · 0.90
__init__Method · 0.90
__init__Method · 0.90
__call__Method · 0.70
transform_flow.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected