How do I remove the gray border from a rotated image using skimage?

I want to remove the gray border that comes up when rotating an image using skimage.transform.rotate . I rather use the skimage library because on Pillow the rotated images come out more pixilated. Here is an example using a yellow rotated image on a white background:

from skimage import transform
from skimage.io import imread, imshow, imsave
from PIL import Image

# white background
bg = Image.new('RGB', (557, 558), (255, 255, 255))
bg = bg.convert('RGBA')

# yellow image
y = Image.new('RGB', (557, 558), (254, 255, 14))
y = y.convert('RGBA')
y.save('yellow.png')

# rotated yellow image in skimage
y = imread('yellow.png')
rotate = transform.rotate(y, 20)
imsave('rotated.png', rotate)

# read rotated image in Pillow
rt = Image.open('rotated.png')

# superimpose yellow image on white background
com1 = Image.alpha_composite(bg, rt).convert('RGB')
com1.show()

Source: Python Questions

LEAVE A COMMENT