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

Function padding_resize

tools/preprocess/utils.py:126–156  ·  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

124
125
126def padding_resize(img_ori, height=512, width=512, padding_color=(0, 0, 0), interpolation=cv2.INTER_LINEAR):
127 ori_height = img_ori.shape[0]
128 ori_width = img_ori.shape[1]
129 channel = img_ori.shape[2]
130
131 img_pad = np.zeros((height, width, channel))
132 if channel == 1:
133 img_pad[:, :, 0] = padding_color[0]
134 else:
135 img_pad[:, :, 0] = padding_color[0]
136 img_pad[:, :, 1] = padding_color[1]
137 img_pad[:, :, 2] = padding_color[2]
138
139 if (ori_height / ori_width) > (height / width):
140 new_width = int(height / ori_height * ori_width)
141 img = cv2.resize(img_ori, (new_width, height), interpolation=interpolation)
142 padding = int((width - new_width) / 2)
143 if len(img.shape) == 2:
144 img = img[:, :, np.newaxis]
145 img_pad[:, padding : padding + new_width, :] = img
146 else:
147 new_height = int(width / ori_width * ori_height)
148 img = cv2.resize(img_ori, (width, new_height), interpolation=interpolation)
149 padding = int((height - new_height) / 2)
150 if len(img.shape) == 2:
151 img = img[:, :, np.newaxis]
152 img_pad[padding : padding + new_height, :, :] = img
153
154 img_pad = np.uint8(img_pad)
155
156 return img_pad
157
158
159def get_frame_indices(frame_num, video_fps, clip_length, train_fps):

Callers 3

__call__Method · 0.90
process_input_videoFunction · 0.90
resize_by_areaFunction · 0.85

Calls 1

resizeMethod · 0.45

Tested by

no test coverage detected