pillow的数据增强功能

下面展示 getAugmentionJPG.py

展示pillow的数据增强功能
import os
import shutil
from PIL import Image
from PIL import ImageFilter

sourcePath = "train"
# sourcePath = "test" 
destinationPath_CONTOUR = sourcePath + "_CONTOUR/"
destinationPath_DETAIL = sourcePath + "_DETAIL/"
destinationPath_EDGE_ENHANCE = sourcePath + "_EDGE_ENHANCE/"
destinationPath_EMBOSS = sourcePath + "_EMBOSS/"
destinationPath_FIND_EDGES = sourcePath + "_FIND_EDGES/"
destinationPath_SHARPEN = sourcePath + "_SHARPEN/"



for filename in os.listdir(sourcePath): # 2020-03-13_07#59#45.jpg   label.txt
    fileNameStr = str(filename)
    if fileNameStr.endswith(".txt"):
        shutil.copyfile(os.path.join(sourcePath,fileNameStr), os.path.join(destinationPath_CONTOUR,fileNameStr))
        shutil.copyfile(os.path.join(sourcePath,fileNameStr), os.path.join(destinationPath_DETAIL,fileNameStr))
        shutil.copyfile(os.path.join(sourcePath,fileNameStr), os.path.join(destinationPath_EDGE_ENHANCE,fileNameStr))
        shutil.copyfile(os.path.join(sourcePath,fileNameStr), os.path.join(destinationPath_EMBOSS,fileNameStr))
        shutil.copyfile(os.path.join(sourcePath,fileNameStr), os.path.join(destinationPath_FIND_EDGES,fileNameStr))
        shutil.copyfile(os.path.join(sourcePath,fileNameStr), os.path.join(destinationPath_SHARPEN,fileNameStr))
        # print(fileNameStr)
    if fileNameStr.endswith(".jpg"):
        fileNameStrStripSuffix = fileNameStr[:-4]
        im = Image.open(os.path.join(sourcePath,fileNameStr))
        # print("图片读取成功...")

        im_CONTOUR = im.filter(ImageFilter.CONTOUR)
        im_CONTOUR.save( destinationPath_CONTOUR+fileNameStr)

        im_DETAIL = im.filter(ImageFilter.DETAIL)
        im_DETAIL.save( destinationPath_DETAIL+fileNameStr)

        im_EDGE_ENHANCE = im.filter(ImageFilter.EDGE_ENHANCE)
        im_EDGE_ENHANCE.save( destinationPath_EDGE_ENHANCE+fileNameStr)

        im_EMBOSS = im.filter(ImageFilter.EMBOSS)
        im_EMBOSS.save( destinationPath_EMBOSS+fileNameStr)

        im_FIND_EDGES = im.filter(ImageFilter.FIND_EDGES)
        im_FIND_EDGES.save( destinationPath_FIND_EDGES+fileNameStr)

        im_SHARPEN = im.filter(ImageFilter.SHARPEN)
        im_SHARPEN.save( destinationPath_SHARPEN+fileNameStr)



    # print(newName) # 2020-03-13_07#59#45.jpg label.txt
    # newName = newName.replace(' ', '')
    # os.rename(os.path.join(sourcePath,filename),os.path.join(sourcePath,newName))
    # print("文件: ",filename,"--->",newName," 重命名已完成!") 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值