13、随机旋转 transforms.RandomRotation()

transforms.RandomRotation(degrees, interpolation=<InterpolationMode.NEAREST: 'nearest'>, expand=False, center=None, fill=0, resample=None)
expand:可选扩展标志。如果为true,则扩展输出,使其足够大,以容纳整个旋转图像。如果为false或省略,请使输出图像与输入图像大小相同。
import torchvision.transforms as transform
from PIL import Image
import matplotlib.pyplot as plt
import numpy as np
import torch
img0=Image.open('lin-xiao-xun-000003.jpg')
img1=transform.RandomRotation(45)(img0)
img2=transform.RandomRotation(45,expand=True)(img0)
img3=transform.RandomRotation(45,center=(45,45))(img0)
axs = plt.figure().subplots(1, 4)
axs[0].imshow(img0);axs[0].set_title('src');axs[0].axis('off')
axs[1].imshow(img1);axs[1].set_title('45');axs[1].axis('off')
axs[2].imshow(img2);axs[2].set_title('expand');axs[2].axis('off')
axs[3].imshow(img3);axs[3].set_title('center');axs[3].axis('off')
plt.show()

实图演示:

13、随机旋转 transforms.RandomRotation()_第1张图片

你可能感兴趣的:(pytorch数据增强方法,python,计算机视觉,opencv)