具体代码执行如下:
#coding=utf-8
from PIL import Image
import os
import os.path
#图片的水平翻转
rootdir = r'/home/qxq/Desktop/eyedata_final/mask/rotation/' # 指明被遍历的文件夹
for parent, dirnames, filenames in os.walk(rootdir):
for filename in filenames:
# print('parent is :' + parent)
# print('filename is :' + filename)
currentPath = os.path.join(parent, filename)
# print('the fulll name of the file is :' + currentPath)
im = Image.open(currentPath)
out = im.transpose(Image.FLIP_LEFT_RIGHT) #左右翻转
newname = r"/home/qxq/Desktop/eyedata_final/mask/flip/" + 'flip_' + filename
out.save(newname)