【OpenCV】⚠️高手勿入! 半小时学会基本操作 18⚠️ 图像金字塔

29 篇文章 74 订阅

【OpenCV】⚠️高手勿入! 半小时学会基本操作 18⚠️

概述

OpenCV 是一个跨平台的计算机视觉库, 支持多语言, 功能强大. 今天小白就带大家一起携手走进 OpenCV 的世界. (第 18 课)

在这里插入图片描述

图像金字塔

在这里插入图片描述

高斯金字塔

高斯金字塔 (Gaussian Pyramid) 是最基本的图像塔. 对图像进行高斯滤波, 然后去除偶数行和列. 对图像放大形成上采样.

下采样:
在这里插入图片描述

例子:

# 读取图片
img = cv2.imread("person.jpg")
print(img.shape)  # (381, 382, 3)

# 下采样
down = cv2.pyrDown(img)
print(down.shape)  # (191, 191, 3)

# 展示图片
cv2.imshow("down", down)
cv2.waitKey(0)
cv2.destroyAllWindows()

上采样:
在这里插入图片描述

例子:

# 读取图片
img = cv2.imread("person.jpg")
print(img.shape)  # (381, 382, 3)

# 上采样
up = cv2.pyrUp(img)
print(up.shape)  # (762, 764, 3)

# 展示图片
cv2.imshow("up", up)
cv2.waitKey(0)
cv2.destroyAllWindows()

下采样然后上采样 vs 原图:

# 读取图片
img = cv2.imread("person.jpg")
img = cv2.resize(img, (380, 380))

# 下采样
down = cv2.pyrDown(img)

# 上采样
down_up = cv2.pyrUp(down)

# 组合
combine = np.hstack((img, down_up))

# 图片展示
cv2.imshow("combine", combine)
cv2.waitKey(0)
cv2.destroyAllWindows()

输出结果:

在这里插入图片描述
从上图我们可以看出, 原图明显比下采样然后上采样的图清晰.

拉布拉斯金字塔

在进行高斯金字塔 (Gaussian Pyramid) 运算时, 在不断的高斯滤波和下采样, 我们丢失了很多高频信号.

拉斯金字塔 (Laplacian Pyramid) 可以帮助我们保留高频信号.

在这里插入图片描述
代码:

# 读取图片
img = cv2.imread("person.jpg")
img = cv2.resize(img, (380, 380))

# 下采样
down = cv2.pyrDown(img)

# 上采样
down_up = cv2.pyrUp(down)

# 原图 - down_up
result = img - down_up

# 图片展示
cv2.imshow("result", result)
cv2.waitKey(0)
cv2.destroyAllWindows()

输出结果:

在这里插入图片描述

评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值