MCPcopy Create free account
hub / github.com/ModelTC/LightX2V / resize_by_area

Function resize_by_area

tools/preprocess/utils.py:105–123  ·  view source on GitHub ↗
(image, target_area, keep_aspect_ratio=True, divisor=64, padding_color=(0, 0, 0))

Source from the content-addressed store, hash-verified

103
104
105def resize_by_area(image, target_area, keep_aspect_ratio=True, divisor=64, padding_color=(0, 0, 0)):
106 h, w = image.shape[:2]
107 try:
108 new_w, new_h = calculate_new_size(w, h, target_area, divisor)
109 except: # noqa
110 aspect_ratio = w / h
111
112 if keep_aspect_ratio:
113 new_h = math.sqrt(target_area / aspect_ratio)
114 new_w = target_area / new_h
115 else:
116 new_w = new_h = math.sqrt(target_area)
117
118 new_w, new_h = int((new_w // divisor) * divisor), int((new_h // divisor) * divisor)
119
120 interpolation = cv2.INTER_AREA if (new_w * new_h < w * h) else cv2.INTER_LINEAR
121
122 resized_image = padding_resize(image, height=new_h, width=new_w, padding_color=padding_color, interpolation=interpolation)
123 return resized_image
124
125
126def padding_resize(img_ori, height=512, width=512, padding_color=(0, 0, 0), interpolation=cv2.INTER_LINEAR):

Callers 2

__call__Method · 0.90
process_input_videoFunction · 0.90

Calls 2

calculate_new_sizeFunction · 0.85
padding_resizeFunction · 0.85

Tested by

no test coverage detected