当前位置:网站首页>图像合并水平拼接
图像合并水平拼接
2022-08-04 05:29:00 【CV小Rookie】
import PIL.Image as Image
import os
# from IPython import embed
# embed()
# 定义图像拼接函数
def image_compose(imag, imag_1):
src = os.path.join(os.path.abspath(IMAGE_SAVE_PATH), img)
to_image = Image.new('RGB', (2 * h, 1 * w)) # 创建一个新图
# 把两张图片按顺序粘贴到对应位置上
rom_image = Image.open(IMAGES_PATH + imag).resize((h, w), Image.ANTIALIAS)
rom_image_1 = Image.open(IMAGES_PATH_1 + imag_1).resize((h, w), Image.ANTIALIAS)
to_image.paste(rom_image, (0, 0))
to_image.paste(rom_image_1, (h, 0))
to_image.save(src) # 保存新图,还是原来的名称
if __name__ == '__main__':
IMAGES_PATH = '/Users/xxx/Downloads/val/1/' # left image
IMAGES_PATH_1 = '/Users/xxx/Downloads/2/' # right image
IMAGE_SAVE_PATH = '/Users/xxx/Downloads/3/' # new image
IMAGES_FORMAT = ['.jpg'] # 图片格式 jpg png都可以
list_n = []
w = 512 # 每张小图片的大小
h = 512
# 获取图片集地址下的所有图片名称
image_names = [name for name in os.listdir(IMAGES_PATH) for item in IMAGES_FORMAT if
os.path.splitext(name)[1] == item]
image_names_1 = [name for name in os.listdir(IMAGES_PATH_1) for item in IMAGES_FORMAT if
os.path.splitext(name)[1] == item]
# 文件名相同就调用拼接函数
for img in image_names:
for img_1 in image_names_1:
if img == img_1:
image_compose(img, img_1)
边栏推荐
猜你喜欢
Logistic Regression --- Introduction, API Introduction, Case: Cancer Classification Prediction, Classification Evaluation, and ROC Curve and AUC Metrics
多项式回归(PolynomialFeatures)
TensorFlow2学习笔记:4、第一个神经网模型,鸢尾花分类
win云服务器搭建个人博客失败记录(wordpress,wamp)
TensorFlow2 study notes: 6. Overfitting and underfitting, and their mitigation solutions
RecyclerView的用法
(十三)二叉排序树
两个APP进行AIDL通信
EPSON RC+ 7.0 使用记录一
k9s-终端UI工具
随机推荐
k9s-终端UI工具
postgresql 事务隔离级别与锁
Jupyter Notebook installed library;ModuleNotFoundError: No module named 'plotly' solution.
动手学深度学习_线性回归
剑指 Offer 2022/7/8
剑指 Offer 2022/7/4
Kubernetes基本入门-集群资源(二)
MySql--存储引擎以及索引
TensorFlow:tf.ConfigProto()与Session
TensorFlow2 study notes: 6. Overfitting and underfitting, and their mitigation solutions
NFT市场以及如何打造一个NFT市场
npm install dependency error npm ERR! code ENOTFOUNDnpm ERR! syscall getaddrinfonpm ERR! errno ENOTFOUND
Simple and clear, the three paradigms of database design
Usage of Thread, Handler and IntentService
剑指 Offer 20226/30
Kubernetes基础入门(完整版)
【CV-Learning】Convolutional Neural Network
Postgresql 快照
(TensorFlow)——tf.variable_scope和tf.name_scope详解
Th in thymeleaf: href use notes