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()
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步