[opencv]图像金字塔

1.图像金字塔

这里介绍两种图像金字塔。
高斯金字塔:用于向下采样。
如下所示:
G0
G1
G2
底层的分辨率最高,越向下采样图像分辨率越低。
由Gi生成Gi+1层:
(1)使用高斯核和Gi层进行卷积运算
(2)将偶数行和列移除。
拉普拉斯金字塔:用于向上采样
如下所示:



向上采样,图像分辨率越来越高。
由Gi生成Gi+1层:
(1)将图像扩大为Gi层的2倍,新增的偶数行列以0进行填充
(2)使用之前的高斯核乘以4与(1)中生成的图像进行卷积

2.opencv函数pyrDown和pyrUp

pyrDown和pyrUp在Image Filtering模块里。
void pyrDown(InputArray src, OutputArray dst, const Size& dstsize=Size())
Parameters:
  • src – Source image.
  • dst – Destination image. It has the specified size and the same type as src .
  • dstsize –

    Size of the destination image. By default, it is computed as Size((src.cols+1)/2, (src.rows+1)/2) . But in any case, the following conditions should be satisfied:


The function performs the downsampling step of the Gaussian pyramid construction. First, it convolves the source image with the kernel:


Then, it downsamples the image by rejecting even rows and columns.


void pyrUp(InputArray src, OutputArray dst, const Size& dstsize=Size())
Parameters:
  • src – Source image.
  • dst – Destination image. It has the specified size and the same type as src .
  • dstsize –

    Size of the destination image. By default, it is computed as Size(src.cols*2, (src.rows*2) . But in any case, the following conditions should be satisfied:


The function performs the upsampling step of the Gaussian pyramid construction though it can actually be used to construct the Laplacian pyramid. First, it upsamples the source image by injecting even zero rows and columns and then convolves the result with the same kernel as in  pyrDown()  multiplied by 4.

3.演示

#include "stdafx.h"
#include "cv.h"
#include "highgui.h"
#include "math.h"

using namespace cv;
using namespace std;

void Help()
{
	cout << "************使用说明************"<<endl;
	cout <<"按下按键d进行向下采样"<< endl;
	cout <<"按下按键u进行向上采样"<<endl;
	cout <<"按下按键q退出"<<endl;
}

int _tmain(int argc, _TCHAR* argv[])
{
	Help();
	namedWindow("IMG", 1);
	Mat img = imread("1.jpg");
	while (1)
	{	
		imshow("IMG",img);
		char a = waitKey(0);
		switch (a)
		{
		    case 'd':
				pyrDown(img, img);
				break;
			case 'u':
				pyrUp(img, img);
				break;
			case 'q':
				return 0;
				break;
		}
	}
	return 0;
}
GIF效果如下:



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值