当前位置:网站首页>图像合并水平拼接
图像合并水平拼接
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)
边栏推荐
- android基础 [超级详细android存储方式解析(SharedPreferences,SQLite数据库存储)]
- 【go语言入门笔记】12、指针
- The difference between oracle temporary table and pg temporary table
- 剑指 Offer 2022/7/9
- (十二)树--哈夫曼树
- k9s-终端UI工具
- [Deep Learning 21 Days Learning Challenge] Memo: What does our neural network model look like? - detailed explanation of model.summary()
- Learning curve learning_curve function in sklearn
- (五)栈及其应用
- 【深度学习21天学习挑战赛】2、复杂样本分类识别——卷积神经网络(CNN)服装图像分类
猜你喜欢
Kubernetes基本入门-概念介绍(一)

Install dlib step pit record, error: WARNING: pip is configured with locations that require TLS/SSL

多项式回归(PolynomialFeatures)

动手学深度学习_卷积神经网络CNN

剑指 Offer 2022/7/1

网络大作业心得笔记

【go语言入门笔记】13、 结构体(struct)

npm install dependency error npm ERR! code ENOTFOUNDnpm ERR! syscall getaddrinfonpm ERR! errno ENOTFOUND

TensorFlow2学习笔记:8、tf.keras实现线性回归,Income数据集:受教育年限与收入数据集

ReentrantLock(公平锁、非公平锁)可重入锁原理
随机推荐
flink自定义轮询分区产生的问题
图像形变(插值方法)
剑指 Offer 2022/7/3
组原模拟题
postgres recursive query
读研碎碎念
Jupyter Notebook安装库;ModuleNotFoundError: No module named ‘plotly‘解决方案。
ReentrantLock(公平锁、非公平锁)可重入锁原理
postgresql 游标(cursor)的使用
【深度学习21天学习挑战赛】备忘篇:我们的神经网模型到底长啥样?——model.summary()详解
(五)栈及其应用
postgresql中创建新用户等各种命令
The use of the attribute of the use of the animation and ButterKnife
【go语言入门笔记】12、指针
TensorFlow2 study notes: 4. The first neural network model, iris classification
简单明了,数据库设计三大范式
SQL练习 2022/7/4
Redis持久化方式RDB和AOF详解
SQL练习 2022/7/5
Dictionary feature extraction, text feature extraction.