python批量处理图片颜色反转

本文介绍如何使用Python的PIL库来批量处理图片,实现颜色反转的效果。通过读取图片文件,应用颜色反转的图像处理函数,再保存处理后的图片,可以高效地对大量图片进行处理。
摘要由CSDN通过智能技术生成
#coding:utf-8
import os
from PIL import Image
import numpy as np

def resize(imgPath,savePath):
    files = os.listdir(imgPath)
    files.sort()
    print('****************')
    print('input :',imgPath)
    print('start...')
    for file in files:
        fileType = os.path.splitext(file)
        if fileType[1] == '.jpg':
            new_png = Image.open(imgPath+'/'+file) #打开图片
            #new_png = new_png.resize((20, 20),Image.ANTIALIAS) #改变图片大小
            matrix = 255-np.asarray(new_png) #图像转矩阵 并反色
            new_png = Image.fromarray(matrix) #矩阵转图像
            new_png.save(savePath+'/'+file) #保存图片
    print('down!')
    print('****************')

if __name__ == '__main__':
    # 待处理图片地址
    dataPath = 'F:\\clean_images\\profiles\\'
    #保存图片的地址
    savePath = 'F:\\clean_images\\new_mask
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值