#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
python批量处理图片颜色反转
最新推荐文章于 2024-07-20 03:51:09 发布
本文介绍如何使用Python的PIL库来批量处理图片,实现颜色反转的效果。通过读取图片文件,应用颜色反转的图像处理函数,再保存处理后的图片,可以高效地对大量图片进行处理。
摘要由CSDN通过智能技术生成