python + opencv图像处理(十七)——图像金字塔

图像金字塔原理
高斯金字塔与拉普拉斯金字塔
reduce = 高斯模糊+降采样
expand = 扩大 + 卷积
PyrDown:降采样
PyrUp:还原

from matplotlib import pyplot as plt 
from cv2 import cv2 as cv
import numpy as np 

# 高斯金字塔
def pyramid_demo(image):
    level = 3   #层数
    temp = image.copy()
    pyramid_images = []
    for i in range(level):
        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)

if __name__ == '__main__':
	filepath = "C:\\pictures\\cat.jpg"  # 对于这样 图片必须是2^n 格式如(512*512)
	img = cv.imread(filepath)       # blue green red
	# cv.namedWindow("input image",cv.WINDOW_AUTOSIZE)
	cv.imshow("input image",img)
	
	lapalian_demo(img)
	
	cv.waitKey(0)
	cv.destroyAllWindows()

拉普拉斯:
在这里插入图片描述
高斯:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

xiao黄

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

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

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

打赏作者

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

抵扣说明:

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

余额充值