Python实现图片拼接的代码
具体代码如下所示:
import os from PIL import Image UNIT_SIZE = 220 # the size of image save_path = '/root/group-dia/zxb/Code-/lip-CycleGAN-and-pix2pix-master/checkpoints/lip_cyclegan_6.0/web/result/out' path = "/root/group-dia/zxb/Code-/lip-CycleGAN-and-pix2pix-master/checkpoints/lip_cyclegan_6.0/web/images" images = [] def pinjie(images): for i in range(len(images) / 6): target = Image.new('RGB', (UNIT_SIZE*3, UNIT_SIZE*2)) # result is 2*3 leftone = 0 lefttwo = 0 rightone = UNIT_SIZE righttwo = UNIT_SIZE for j in range(6): if(j <= 2): target.paste(images[j + i*6], (leftone, 0, rightone, UNIT_SIZE)) leftone += UNIT_SIZE rightone += UNIT_SIZE else: target.paste(images[j + i*6], (lefttwo, UNIT_SIZE, righttwo, UNIT_SIZE*2)) lefttwo += UNIT_SIZE righttwo += UNIT_SIZE quality_value = 500 target.save(save_path + '{}.png'.format(i), quality=quality_value) if __name__ == '__main__': for img in os.listdir(path): images.append(Image.open(os.path.join(path, img))) print len(images) pinjie(images)
总结
相关推荐
YENCSDN 2020-11-17
lsjweiyi 2020-11-17
houmenghu 2020-11-17
Erick 2020-11-17
HeyShHeyou 2020-11-17
以梦为马不负韶华 2020-10-20
lhtzbj 2020-11-17
夜斗不是神 2020-11-17
pythonjw 2020-11-17
dingwun 2020-11-16
lhxxhl 2020-11-16
坚持是一种品质 2020-11-16
染血白衣 2020-11-16
huavhuahua 2020-11-20
meylovezn 2020-11-20
逍遥友 2020-11-20
weiiron 2020-11-16