MCPcopy
hub / github.com/Wan-Video/Wan2.2 / padding_resize

Function padding_resize

wan/modules/animate/preprocess/utils.py:158–188  ·  view source on GitHub ↗
(img_ori, height=512, width=512, padding_color=(0, 0, 0), interpolation=cv2.INTER_LINEAR)

Source from the content-addressed store, hash-verified

156
157
158def padding_resize(img_ori, height=512, width=512, padding_color=(0, 0, 0), interpolation=cv2.INTER_LINEAR):
159 ori_height = img_ori.shape[0]
160 ori_width = img_ori.shape[1]
161 channel = img_ori.shape[2]
162
163 img_pad = np.zeros((height, width, channel))
164 if channel == 1:
165 img_pad[:, :, 0] = padding_color[0]
166 else:
167 img_pad[:, :, 0] = padding_color[0]
168 img_pad[:, :, 1] = padding_color[1]
169 img_pad[:, :, 2] = padding_color[2]
170
171 if (ori_height / ori_width) > (height / width):
172 new_width = int(height / ori_height * ori_width)
173 img = cv2.resize(img_ori, (new_width, height), interpolation=interpolation)
174 padding = int((width - new_width) / 2)
175 if len(img.shape) == 2:
176 img = img[:, :, np.newaxis]
177 img_pad[:, padding: padding + new_width, :] = img
178 else:
179 new_height = int(width / ori_width * ori_height)
180 img = cv2.resize(img_ori, (width, new_height), interpolation=interpolation)
181 padding = int((height - new_height) / 2)
182 if len(img.shape) == 2:
183 img = img[:, :, np.newaxis]
184 img_pad[padding: padding + new_height, :, :] = img
185
186 img_pad = np.uint8(img_pad)
187
188 return img_pad
189
190
191def get_frame_indices(frame_num, video_fps, clip_length, train_fps):

Callers 2

__call__Method · 0.90
resize_by_areaFunction · 0.85

Calls 1

resizeMethod · 0.80

Tested by

no test coverage detected