Skimage:旋转图像并填充新形成的背景

Ada*_*rti 3 python scikit-image

使用旋转图像时

import skimage

result = skimage.transform.rotate(img, angle=some_angle, resize=True)
# the result is the rotated image with black 'margins' that fill the blanks
Run Code Online (Sandbox Code Playgroud)

该算法旋转图像但将新形成的背景保留为黑色,并且无法使用旋转功能选择新形成背景的颜色。

您知道如何在旋转图像之前选择背景颜色吗?

谢谢你。

小智 6

只需使用cval参数

img3 = transform.rotate(img20, 45, resize=True, cval=1, mode ='constant')
img4 = img3 * 255
Run Code Online (Sandbox Code Playgroud)