【使用python将多张图片拼接 小图拼接大图 图片拼接】

使用python将多张图片拼接 小图拼接大图 图片拼接

代码:

dic = "D:\\python-workspace\\my_yolo\\ultralytics\\final_mask_1\\"  #待合并图片文件夹  your small images directory
'''

将多个小图合并成大图   combine small picture to a big one

fileNum  合并数量, numbers of small images
row      行数
col      列数
'''
def combineImage(fileNum,row,col):

    x = 0
    y = 0

    big_picture = np.full((1024 * row, 1024 * col, 3), 255, dtype=np.uint8)  #1024表示图片尺寸,按照自己的设置,我这边图片(小)尺寸为1024*1024 (1024 is the size of the your small picture)
    #big_picture = np.full((25182, 23315, 3), 255, dtype=np.uint8)

    for epoch in range(fileNum):
        pic = cv2.imread(dic+str(epoch+1)+".png")
        if((epoch)%col == 0):
            x = 1024
            y = y + pic.shape[0]
        else:
            x = x + pic.shape[1]
        big_picture[(y-pic.shape[0]):y,(x-pic.shape[1]):x,:] = pic
    cv2.imwrite("big_result.png",cv2.cvtColor(big_picture,cv2.COLOR_BGR2RGB))

拼接结果如下:
在这里插入图片描述
在这里插入图片描述

github完整代码

  • 10
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值