图像的一些扩增方法

制作数据集时,直接对原始文件夹中的图像扩增使用的方法,使用了PIL库中的Image函数

from PIL import Image
#读取图像
im=Image.open('文件名')

1.缩放

im_resized=im.resize(32,32)

2.旋转

#逆时针90
im_90=im.transpose(Image.ROTATE_90)
#逆时针180
im_180=im.transpose(Image.ROTATE_180)
#逆时针270
im_270=im.transpose(Image.ROTATE_270)

#也可以使用rotate()函数
im_45=im.rotate(45)

3.翻转

#左右翻转
im_lr=im.transpose(Image.FLIP_LEFT_RIGHT)
#上下翻转

im_ud=im.transpose(Image.FLIP_TOP_BOTTOM)

猜你喜欢

转载自blog.csdn.net/space_dandy/article/details/108473233