Torchvision.transforms.functional.rotate( fill with nearest pixels

Rotate, but instead of filling the corners with a single color, fill with the nearest pixels’ colors, how ?

Ok, since I didn’t find an official solution, mine:

frame_removal_length = 3
padding = max(IMAGE_SIZE[0], IMAGE_SIZE[1])
rgb = T.functional.resized_crop(rgb, frame_removal_length, frame_removal_length, IMAGE_SIZE[0] - 2 * frame_removal_length, IMAGE_SIZE[1] - 2 * frame_removal_length, IMAGE_SIZE) # Only if the image has some kind of a frame needed to be remvoed.
rgb = T.Pad(padding=padding, fill=0, padding_mode=‘edge’)(rgb)
rgb = T.functional.rotate(img=rgb, angle=degree_to_rotate, fill=(0,) * len(rgb.getbands()))
rgb = T.functional.resized_crop(rgb, padding, padding, IMAGE_SIZE[0], IMAGE_SIZE[1], IMAGE_SIZE)

Enjoy !

1 Like