MCPcopy Create free account
hub / github.com/VCIP-RGBD/DFormer / random_crop

Function random_crop

utils/transforms.py:173–192  ·  view source on GitHub ↗
(img, gt, size)

Source from the content-addressed store, hash-verified

171
172
173def random_crop(img, gt, size):
174 if isinstance(size, numbers.Number):
175 size = (int(size), int(size))
176 else:
177 size = size
178
179 h, w = img.shape[:2]
180 crop_h, crop_w = size[0], size[1]
181
182 if h > crop_h:
183 x = random.randint(0, h - crop_h + 1)
184 img = img[x : x + crop_h, :, :]
185 gt = gt[x : x + crop_h, :]
186
187 if w > crop_w:
188 x = random.randint(0, w - crop_w + 1)
189 img = img[:, x : x + crop_w, :]
190 gt = gt[:, x : x + crop_w]
191
192 return img, gt
193
194
195def normalize(img, mean, std):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected