opencv学习笔记python实现 图像金字塔(高斯金字塔与拉普拉斯金字塔)

使用拉普拉斯金字塔时,图像必须是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()

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

wym_king

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值