1. 程式人生 > >第十三天 高斯金字塔拉普拉斯金字塔

第十三天 高斯金字塔拉普拉斯金字塔

import cv2 as cv
import numpy as np


def pyramid_demo(image):        ##高斯金字塔
    levels =3
    temp = image.copy()
    pyramid_images = []
    for i in range(levels):
        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 = cv.imread("C:/Users/weiqiangwen/Desktop/sest/lena.png")
# cv.namedWindow("input contours",cv.WINDOW_AUTOSIZE)
cv.imshow("contours", src)
#pyramid_demo(src)
lapalian_demo(src)
cv.waitKey(0)

cv.destroyAllWindows()