#encoding:utf-8
## Used to resize pictures
import os
import re
import os.path
from PIL import Image
UNIT_SIZE = 480
TARGET_WIDTH = 2 * UNIT_SIZE
# Image.MAX_IMAGE_PIXELS = 1000000000
# img_file:图片的路径
# path_save:保存路径
# width:宽度
# height:长度
def img_resize(img_file, width,height):
img = Image.open(img_file).convert('RGB')
new_image = img.resize((width,height),Image.ANTIALIAS).convert('RGB')
return new_image
input_path = 'Ink_and_wash/'
output_path = 'Ink_and_wash/train'
if not os.path.exists(output_path):
os.makedirs(output_path)
os.system("rm "+output_path)
file_list = os.listdir(input_path + "trainA")
for index,file_name in enumerate(file_list):
file_path = os.path.join(input_path + "trainA",file_name)
file_path_B = os.path.join(input_path + "trainB", file_name)
if re.findall(".jpg",file_path):
imgA = img_resize(file_path,480,320)
imgB = img_resize(file_path_B,480,320)
output_file_path = os.path.join(output_path,os.path.basename(file_path))
output_file_path=unicode(output_file_path,'utf-8')
target = Image.new('RGB', (TARGET_WIDTH, 320))
target.paste(imgA, (0, 0))
target.paste(imgB, (UNIT_SIZE, 0))
target.save(output_file_path)
网友评论