- OpenCV Python 教程
- OpenCV Python - 主页
- OpenCV Python - 概述
- OpenCV Python - 环境
- OpenCV Python - 读取图像
- OpenCV Python - 写入图像
- OpenCV Python - 使用 Matplotlib
- OpenCV Python - 图像属性
- OpenCV Python - 位运算
- OpenCV Python - 形状和文本
- OpenCV Python - 鼠标事件
- OpenCV Python - 添加轨迹栏
- OpenCV Python - 调整大小和旋转
- OpenCV Python - 图像阈值
- OpenCV Python - 图像过滤
- OpenCV Python - 边缘检测
- OpenCV Python - 直方图
- OpenCV Python - 颜色空间
- OpenCV Python - 转换
- OpenCV Python - 图像轮廓
- OpenCV Python - 模板匹配
- OpenCV Python - 图像Pyramid
- OpenCV Python - 图像相加
- OpenCV Python - 图像混合
- OpenCV Python - 傅里叶变换
- OpenCV Python - 捕获视频
- OpenCV Python - 播放视频
- OpenCV Python - 视频图像
- OpenCV Python - 来自图像的视频
- OpenCV Python - 人脸检测
- OpenCV Python - Meanshift/Camshift
- OpenCV Python - 特征检测
- OpenCV Python - 特征匹配
- OpenCV Python - 数字识别
- OpenCV Python 资源
- OpenCV Python - 快速指南
- OpenCV Python - 资源
- OpenCV Python - 讨论
OpenCV Python - 使用Pyramid进行图像混合
通过使用图像Pyramid可以最小化图像的不连续性。这会产生无缝混合图像。
采取以下步骤来实现最终结果 -
首先加载图像并找到两者的高斯Pyramid。其程序如下 -
import cv2 import numpy as np,sys kalam = cv2.imread('kalam.jpg') einst = cv2.imread('einstein.jpg') ### generate Gaussian pyramid for first G = kalam.copy() gpk = [G] for i in range(6): G = cv2.pyrDown(G) gpk.append(G) # generate Gaussian pyramid for second G = einst.copy() gpe = [G] for i in range(6): G = cv2.pyrDown(G) gpe.append(G)
从高斯Pyramid中,获得相应的拉普拉斯Pyramid。其程序如下 -
# generate Laplacian Pyramid for first lpk = [gpk[5]] for i in range(5,0,-1): GE = cv2.pyrUp(gpk[i]) L = cv2.subtract(gpk[i-1],GE) lpk.append(L) # generate Laplacian Pyramid for second lpe = [gpe[5]] for i in range(5,0,-1): GE = cv2.pyrUp(gpe[i]) L = cv2.subtract(gpe[i-1],GE) lpe.append(L)
然后,在每一层Pyramid中将第一张图像的左半部分与第二张图像的右半部分连接起来。其程序如下 -
# Now add left and right halves of images in each level LS = [] for la,lb in zip(lpk,lpe): rows,cols,dpt = la.shape ls = np.hstack((la[:,0:int(cols/2)], lb[:,int(cols/2):])) LS.append(ls)
最后,从这个联合Pyramid重建图像。下面给出了相同的程序 -
ls_ = LS[0] for i in range(1,6): ls_ = cv2.pyrUp(ls_) ls_ = cv2.add(ls_, LS[i]) cv2.imshow('RESULT',ls_)
输出
混合结果应如下 -