#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\’
resize(dataPath,savePath)
作者:echo_1994
来源:CSDN
原文:https://blog.csdn.net/echo_1994/article/details/85117284
版权声明:本文为博主原创文章,转载请附上博文链接!