python实现拉普拉斯图像金字塔

一,定义

 

 

二,代码:

要求:拉普拉斯金字塔时,图像大小必须是2的n次方*2的n次方,不然会报错

 1 # -*- coding=GBK -*-
 2 import cv2 as cv
 3  
 4  
 5 #高斯金字塔
 6 def pyramid_image(image):
 7     level = 3#金字塔的层数
 8     temp = image.copy()#拷贝图像
 9     pyramid_images = []
10     for i in range(level):
11         dst = cv.pyrDown(temp)
12         pyramid_images.append(dst)
13         cv.imshow("高斯金字塔"+str(i), dst)
14         temp = dst.copy()
15     return pyramid_images
16  
17  
18 #拉普拉斯金字塔
19 def laplian_image(image):
20     pyramid_images = pyramid_image(image)
21     level = len(pyramid_images)
22     for i in range(level-1, -1, -1):
23         if(i-1) < 0 :
24             expand = cv.pyrUp(pyramid_images[i], dstsize=image.shape[:2])
25             lpls = cv.subtract(image, expand)
26             cv.imshow("拉普拉斯"+str(i), lpls)
27         else:
28             expand = cv.pyrUp(pyramid_images[i], dstsize=pyramid_images[i-1].shape[:2])
29             lpls = cv.subtract(pyramid_images[i-1], expand)
30             cv.imshow("拉普拉斯"+str(i), lpls)
31  
32 src = cv.imread("C://01.jpg")
33 cv.imshow("原来", src)
34 laplian_image(src)
35 cv.waitKey(0)
36 cv.destroyAllWindows()

 

posted @ 2020-09-01 10:56  山那边不是山  阅读(2269)  评论(2编辑  收藏  举报