You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hunjianghu/gzy/tesorflow/分辨率归一化+灰度处理.py

24 lines
702 B

import os
from PIL import Image
PATH = 'D:/tensorflow/未处理的训练源/'
PATH2 = 'D:/tensorflow/train/'
def resize_image(img_path,save_path):
total = 0
try:
for pic in os.listdir(img_path):
path = img_path+pic
image = Image.open(path).convert('L')
new_pic = image.resize((60,60),Image.ANTIALIAS)
new_path = save_path+str(total)+'.jpg'
new_pic.save(new_path,quality=100)
total = total+1
except Exception as e:
print(e)
if __name__ == '__main__':
for page in range(1,6):
print("During deal with %d"%(page))
resize_image(PATH+str(page)+'/',PATH2+str(page)+'/')