1、图像金字塔原理:
reduce = 高斯模糊 + 降采样
降采样:行、列各取偶数行,组成新的图像
expand = 扩大 + 卷积(扩大是升采样)
2、经过reduce的图像是高斯金字塔
L1 = g1 - expand(g2)得到图像的轮廓是拉普拉斯金字塔
import cv2 as cv
import numpy as np
# 金字塔定义
def pyramid_demo(image):
level = 3
temp = image.copy()
pyramid_images = []
for i in range(level):
dst = cv.pyrDown(temp)
pyramid_images.append(dst)
cv.imshow('pyramid_down_'+str(i), dst)
temp = dst.copy()
return pyramid_images
# 拉普拉斯金字塔
def lapalian_demo(image):
pyramid_images = pyramid_demo(image)
level = len(pyramid_images)
for i in range(level-1, -1, -1):
if (i-1) < 0:
expand = cv.pyrUp(pyramid_images[i], dstsize=image.shape[:2])
lpls = cv.subtract(image, expand)
cv.imshow('lapalian_down_' + str(i), lpls)
else:
expand = cv.pyrUp(pyramid_images[i], dstsize=pyramid_images[i-1].shape[:2])
lpls = cv.subtract(pyramid_images[i-1], expand)
cv.imshow('lapalian_down_'+str(i), lpls)
# src的大小必须是2的整数幂大小
src = cv.imread('C:/Users/Y/Pictures/Saved Pictures/lena.png')
cv.namedWindow('input image', cv.WINDOW_AUTOSIZE)
cv.imshow('input image', src)
lapalian_demo(src)
cv.waitKey(0)
cv.destroyAllWindows()
高斯金字塔
拉普拉斯金字塔