11.1 图像金字塔

1. 向下采样

OpenCV 提供了函数 cv2.pyrDown(),用于实现图像高斯金字塔操作中的向下采样,其语法 形式为:
dst = cv2.pyrDown( src[, dstsize[, borderType]] )
其中:

  • dst 为目标图像。
  • src 为原始图像。
  • dstsize 为目标图像的大小。
  • borderType 为边界类型,默认值为 BORDER_DEFAULT ,且这里仅支持BORDER_DEFAULT。

【例 11.1】使用函数 cv2.pyrDown()对一幅图像进行向下采样,观察采样的结果。

import cv2
import numpy as np

img = cv2.imread("/Users/zhaofeier/Desktop/源代码及图像/chapter11/lena.bmp",0)
r1 = cv2.pyrDown(img)
r2 = cv2.pyrDown(r1)
r3 = cv2.pyrDown(r2)

print("img.shape=",img.shape)
print("r1.shape=",r1.shape)
print("r2.shape=",r2.shape)
print("r3.shape=",r3.shape)

cv2.imshow("img",img)
cv2.imshow("result1",r1)
cv2.imshow("result2",r2)
cv2.imshow("result3",r3)

cv2.waitKey()
cv2.destroyAllWindows()

2. 向上采样

在 OpenCV 中,使用函数 cv2.pyrUp()实现图像金字塔操作中的向上采样,其语法形式如下:
dst = cv2.pyrUp( src[, dstsize[, borderType]] )
其中:

  • dst 为目标图像。
  • src 为原始图像。
  • dstsize 为目标图像的大小。
  • borderType 为边界类型,默认值为 BORDER_DEFAULT ,且这里仅支持BORDER_DEFAULT。
    img = cv2.imread(“/Users/zhaofeier/Desktop/源代码及图像/chapter11/lenas.bmp”)
r1 = cv2.pyrUp(img)
r2 = cv2.pyrUp(r1)
r3 = cv2.pyrUp(r2)

print("img.shape=",img.shape)
print("r1.shape=",r1.shape)
print("r2.shape=",r2.shape)
print("r3.shape=",r3.shape)

cv2.imshow("img",img)
cv2.imshow("result1",r1)
cv2.imshow("result2",r2)
cv2.imshow("result3",r3)

cv2.waitKey()
cv2.destroyAllWindows()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

暮棂

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

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

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

打赏作者

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

抵扣说明:

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

余额充值