使用拉普拉斯金字塔时,图像必须是2^n*2*m
使用拉普拉斯金字塔先要知道高斯金字塔
这两种过程是图片缩小与放大
缩小 reduce = 高斯模糊 + 降采样(pyrDown)
放大 expand = 扩大(升采样/pyrUp) + 卷积
#-*-coding:utf-8 -*-
import cv2 as cv
#高斯金字塔
def pyramid_image(image):
cv.imshow("yuan",image)
level = 3#金字塔的层数
temp = image.copy()#拷贝图像
pyramid_images = []
for i in range(level):
dst = cv.pyrDown(temp)
pyramid_images.append(dst)
cv.imshow("pyramid"+str(i), dst)
temp = dst.copy()
return pyramid_images
#拉普拉斯金字塔
def lpls_image(image):
pyramid_images = pyramid_image(image)
level = len(pyramid_images)
for i in range(level-1, -1, -1):#数组下标从0开始 i从金字塔层数-1开始减减
if (i-1)<0:#原图
expand = cv.pyrUp(pyramid_images[i])
lpls = cv.subtract(image, expand)
cv.imshow("lpls_%s" % i, lpls)
else:
expand = cv.pyrUp(pyramid_images[i])
lpls = cv.subtract(pyramid_images[i-1], expand)
cv.imshow("lpls_%s" % i, lpls)
img = cv.imread("d://work//1.jpg")
lpls_image(img)
cv.waitKey(0)
cv.destroyAllWindows()