INNER CODE UNIT · Python
new_w
Shilin-LU/TF-ICON · scripts/app.py:47
new_w = int(SCALE * 256 / aspect_ratio)
new_h = int(SCALE * 256)
else:
new_w = int(SCALE * 256)
new_h = int(SCALE * 256 * aspect_ratio)
# Resize the image and the segmentation map to the new dimensions
image_resize = image.resize((new_w, new_h))
segmentation_map_resize = cv2.resize(np.array(seg_map).astype(np.uint8), (new_w, new_h), interpolation=cv2.INTER_NEAREST)
# Pad the segmentation map to match the target size
padded_segmentation_map = np.zeros((target_size[1], target_size[0]))
start_x = (target_size[1] - segmentation_map_resize.shape[0]) // 2
start_y = (target_size[0] - segmentation_map_resize.shape[1]) // 2
padded_segmentation_map[start_x: start_x + segmentation_map_resize.shape[0], start_y: start_y + segmentation_map_resize.shape[1]] = segmentation_map_resize
# Create a new RGB image with the target size and place the resized image in the center
padded_image = Image.new("RGB", target_size)