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

Function random_crop_pad_to_shape

utils/transforms.py:28–41  ·  view source on GitHub ↗
(img, crop_pos, crop_size, pad_label_value)

Source from the content-addressed store, hash-verified

26
27
28def random_crop_pad_to_shape(img, crop_pos, crop_size, pad_label_value):
29 h, w = img.shape[:2]
30 start_crop_h, start_crop_w = crop_pos
31 assert (start_crop_h < h) and (start_crop_h >= 0)
32 assert (start_crop_w < w) and (start_crop_w >= 0)
33
34 crop_size = get_2dshape(crop_size)
35 crop_h, crop_w = crop_size
36
37 img_crop = img[start_crop_h : start_crop_h + crop_h, start_crop_w : start_crop_w + crop_w, ...]
38
39 img_, margin = pad_image_to_shape(img_crop, crop_size, cv2.BORDER_CONSTANT, pad_label_value)
40
41 return img_, margin
42
43
44def generate_random_crop_pos(ori_size, crop_size):

Callers 1

__call__Method · 0.90

Calls 2

get_2dshapeFunction · 0.85
pad_image_to_shapeFunction · 0.85

Tested by

no test coverage detected