帮助你高效处理图片,扩大训练集数量,提高训练精度。
1.对比度、锐度、亮度
from PIL import Image
from PIL import ImageEnhance
import os
rootdir = r'/media/jidong/code/zdata/val' # 指明被遍历的文件夹
for parent, dirnames, filenames in os.walk(rootdir):
for filename in filenames:
currentPath = os.path.join(parent, filename)
im = Image.open(currentPath)
print(filename)
# enh_con = ImageEnhance.Contrast(im) # 增加对比度
# image_contrasted = enh_con.enhance(0.5)
# newname1 = r"/media/jidong/code/zdata/tr-duib/" + filename
# image_contrasted.save(newname1)
# enh_sha = ImageEnhance.Sharpness(im) # 增加锐度
# image_sharped = enh_sha.enhance(3.0)
# newname2 = r"/media/jidong/code/zdata/vl-sha/" + filename
# image_sharped.save(newname2)
# 增加亮度
enh_bri = ImageEnhance.Brightness(im)
image_brightened =