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: |
|
---|
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: |
|
---|
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效果如下: