
文章目录
- [1 图像金字塔](#1 图像金字塔)
- [2 拉普拉斯金字塔](#2 拉普拉斯金字塔)
1 图像金字塔
高斯金字塔

在 OpenCV 中使用函数 cv2.pyrDown()
,实现图像高斯金字塔操作中的向下采样,使用函数 cv2.pyrUp()
实现图像金字塔操作中的向上采样
py
import cv2
img = cv2.imread('C://Users/Administrator/Desktop/1.jpg') #直接读为灰度图像
print(img.shape)
cv2.imshow("img", img)
img1 = cv2.pyrDown(img)
print(img1.shape)
cv2.imshow("down", img1)
img2 = cv2.pyrUp(img)
print(img2.shape)
cv2.imshow("up", img2)
cv2.waitKey()
cv2.destroyAllWindows()
output
py
(500, 500, 3)
(250, 250, 3)
(1000, 1000, 3)

2 拉普拉斯金字塔

拉普拉斯金字塔的图像看起来就像是边界图,经常被用在图像压缩中。
py
import cv2
img = cv2.imread('C://Users/Administrator/Desktop/1.jpg', 0)
img1 = cv2.pyrDown(img) # 高斯金字塔
cv2.imshow("img1", img1)
temp = cv2.pyrUp(cv2.pyrDown(img1))
cv2.imshow("temp", temp)
img2 = img1 - temp # 拉普拉斯金字塔
cv2.imshow("img2", img2)
cv2.waitKey()
cv2.destroyAllWindows()
