#include "highgui.h"
#include "cv.h"
IplImage* doPyrDown(IplImage* in, int filter = IPL_GAUSSIAN_5x5)
{
//Best to make sure input image is divisible by two
assert(in->width % 2 == 0 && in->height % 2 == 0);
IplImage* out = cvCreateImage(cvSize( in->width/2, in->height/2),in->depth,in->nChannels);
cvPyrDown(in, out); //
return (out);
};
int main(int argc, char** argv){
IplImage* img = cvLoadImage("E:/lena.png");
cvNamedWindow("Input", CV_WINDOW_AUTOSIZE);
cvNamedWindow("Output", CV_WINDOW_AUTOSIZE);
cvShowImage("Input", img);
doPyrDown(img, 0);
cvShowImage("Output", img);
cvWaitKey(0); //必需的
cvReleaseImage(&img);
cvDestroyWindow("Input");
return 0;
}
介绍库函数cvPyrDown、cvPyrUp。
1、 PyrDown
图像的下采样
void cvPyrDown( const CvArr* src, CvArr* dst, int filter=CV_GAUSSIAN_5x5 );
src
输入图像.
dst
输出图像, 宽度和高度应是输入图像的一半 ,传入前必须已经完成初始化
filter
卷积滤波器的类型,目前仅支持 CV_GAUSSIAN_5x5
函数 cvPyrDown 使用 Gaussian 金字塔分解对输入图像向下采样。首先它对输入图像用指定滤波器进行卷积,然后通过拒绝偶数的行与列来下采样图像。
2、 PyrUp
图像的上采样
void cvPyrUp( const CvArr* src, CvArr* dst, int filter=CV_GAUSSIAN_5x5 );
src
输入图像.
dst
输出图像, 宽度和高度应是输入图像的2倍
filter
卷积滤波器的类型,目前仅支持 CV_GAUSSIAN_5x5
函数 cvPyrUp 使用Gaussian 金字塔分解对输入图像向上采样。首先通过在图像中插入 0 偶数行和偶数列,然后对得到的图像用指定的滤波器进行高斯卷积,其中滤波器乘以4做插值。所以输出图像是输入图像的 4 倍大小。