MCPcopy Create free account
hub / github.com/MotrixLab/AiOS / resize

Function resize

util/preprocessing.py:59–93  ·  view source on GitHub ↗
(ori_shape, size, max_size=None)

Source from the content-addressed store, hash-verified

57
58 return bbox
59def resize(ori_shape, size, max_size=None):
60 # size can be min_size (scalar) or (w, h) tuple
61 # import ipdb; ipdb.set_trace(context=15)
62 def get_size_with_aspect_ratio(image_size, size, max_size=None):
63 w, h = image_size
64 if max_size is not None:
65 min_original_size = float(min((w, h)))
66 max_original_size = float(max((w, h)))
67 if min_original_size ==0:
68 print('min_original_size:',min_original_size)
69 if max_original_size / (min_original_size) * size > max_size:
70 size = int(round(max_size * min_original_size / max_original_size))
71
72 if (w <= h and w == size) or (h <= w and h == size):
73 return (w, h)
74
75 if w < h:
76 ow = size
77 oh = int(size * h / w)
78 else:
79 oh = size
80 ow = int(size * w / h)
81
82 return (ow, oh)
83
84 def get_size(ori_shape, size, max_size=None):
85 if isinstance(size, (list, tuple)):
86 return size[::-1]
87 else:
88 return get_size_with_aspect_ratio(ori_shape, size, max_size)
89
90 size = get_size(ori_shape, size, max_size)
91
92
93 return size
94
95def process_bbox(bbox, img_width, img_height, ratio=1.):
96

Callers 2

augmentation_keep_sizeFunction · 0.70

Calls 1

get_sizeFunction · 0.70

Tested by

no test coverage detected