- 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 - 影像金字塔
- OpenCV Python - 影像加法
- OpenCV Python - 影像混合
- OpenCV Python - 傅立葉變換
- OpenCV Python - 捕獲影片
- OpenCV Python - 播放影片
- OpenCV Python - 從影片中提取影像
- OpenCV Python - 從影像生成影片
- OpenCV Python - 人臉檢測
- OpenCV Python - 均值漂移/CamShift
- OpenCV Python - 特徵檢測
- OpenCV Python - 特徵匹配
- OpenCV Python - 數字識別
- OpenCV Python 資源
- OpenCV Python - 快速指南
- OpenCV Python - 資源
- OpenCV Python - 討論
OpenCV Python - 使用金字塔進行影像混合
可以透過使用影像金字塔來最小化影像的不連續性。這將產生一個無縫混合的影像。
為了達到最終效果,需要執行以下步驟:
首先載入影像,併為兩者找到高斯金字塔。相應的程式如下:
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)
從高斯金字塔中,獲得各自的拉普拉斯金字塔。相應的程式如下:
# 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)
然後,在金字塔的每個層級中,將第一張影像的左半部分與第二張影像的右半部分連線起來。相應的程式如下:
# 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)
最後,從這個聯合金字塔中重建影像。相應的程式如下:
ls_ = LS[0]
for i in range(1,6):
ls_ = cv2.pyrUp(ls_)
ls_ = cv2.add(ls_, LS[i])
cv2.imshow('RESULT',ls_)
輸出
混合後的結果應如下所示:
廣告