Python實(shí)現(xiàn)圖片拼接的代碼
更新時(shí)間:2018年07月02日 14:17:50 作者:LemonTree_Summer
本文通過實(shí)例代碼給大家介紹了python實(shí)現(xiàn)圖片拼接的方法,非常不錯(cuò),具有一定的參考借鑒借鑒價(jià)值,需要的朋友參考下吧
具體代碼如下所示:
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)
總結(jié)
以上所述是小編給大家介紹的Python實(shí)現(xiàn)圖片拼接的代碼,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
相關(guān)文章
Keras搭建M2Det目標(biāo)檢測平臺(tái)示例
這篇文章主要為大家介紹了Keras搭建M2Det目標(biāo)檢測平臺(tái)實(shí)現(xiàn)的源碼示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-05-05
Python多線程threading創(chuàng)建及使用方法解析
這篇文章主要介紹了Python多線程threading創(chuàng)建及使用方法解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-06-06
淺談python中對(duì)于json寫入txt文件的編碼問題
今天小編就為大家分享一篇淺談python中對(duì)于json寫入txt文件的編碼問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-06-06

