本文主要是介绍python实现opencv学习十五:高斯金字塔和拉普拉斯金字塔,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
要求:拉普拉斯金字塔时,图像大小必须是2的n次方*2的n次方,不然会报错
代码如下:
# -*- coding=GBK -*-
import cv2 as cv#高斯金字塔
def pyramid_image(image):level = 3#金字塔的层数temp = image.copy()#拷贝图像pyramid_images = []for i in range(level):dst = cv.pyrDown(temp)pyramid_images.append(dst)cv.imshow("高斯金字塔"+str(i), dst)temp = dst.copy()return pyramid_images#拉普拉斯金字塔
def laplian_image(image):pyramid_images = pyramid_image(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("拉普拉斯"+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("拉普拉斯"+str(i), lpls)src = cv.imread("C://01.jpg")
cv.imshow("原来", src)
laplian_image(src)
cv.waitKey(0)
cv.destroyAllWindows()
这篇关于python实现opencv学习十五:高斯金字塔和拉普拉斯金字塔的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!