OpenCV笔记-图像处理之尺寸调整cvResize

函数 原型:

/* Resizes image (input array is resized to fit the destination array) */

CVAPI(void)  cvResize( const CvArr* src, CvArr* dst,

                       int interpolation CV_DEFAULT( CV_INTER_LINEAR ));

src和dst分别为原图像和目标图像

interpolation可取值为:

/* Sub-pixel interpolation methods */

enum

{

    CV_INTER_NN        =0,//最近邻插值

    CV_INTER_LINEAR    =1,//双线性插值

    CV_INTER_CUBIC     =2,//在4*4的邻域内双三次插值

    CV_INTER_AREA      =3,//使用像素面积关系重采样。广泛用于图像抽取的时候

    CV_INTER_LANCZOS4  =4//在8*8的邻域内的Lanczos插值

};

示例代码:

#include <cv.h>

#include <highgui.h>

#include <stdio.h>



int main()

{

    IplImage* image = cvLoadImage("E:\\mls\\fz1\\_MG_0007.JPG");



    CvSize size = cvGetSize(image);

    size.width = 480 * size.height / size.height;

    size.height = 480;



    cvNamedWindow("CV_INTER_NN");

    cvNamedWindow("CV_INTER_LINEAR");

    cvNamedWindow("CV_INTER_AREA");

    cvNamedWindow("CV_INTER_CUBIC");

    cvNamedWindow("CV_INTER_LANCZOS4");



    IplImage* resize1 = cvCreateImage(size, image->depth, image->nChannels);

    IplImage* resize2 = cvCreateImage(size, image->depth, image->nChannels);

    IplImage* resize3 = cvCreateImage(size, image->depth, image->nChannels);

    IplImage* resize4 = cvCreateImage(size, image->depth, image->nChannels);

    IplImage* resize5 = cvCreateImage(size, image->depth, image->nChannels);



    /*cvResize函数支持 ROI*/

    /*

    *    最近邻插值:设原图像高宽为h和w,目标图像高宽为h0和w0,则缩放比例为

    *                float fh=1.0*h/h0;float fw=1.0*w/w0;

    *                则对于目标图像的点p0(x0,y0)对应的原图像的点为p(int(x0*fw),int(y0*fh))

    */

    cvResize(image, resize1, CV_INTER_NN);

    /*

    *    双线性插值 (缺省使用):先按x方向做线性插值再按y方向做线性插值

    */

    cvResize(image, resize2, CV_INTER_LINEAR);

    /*使用象素关系重采样。当图像缩小时候,该方法可以避免波纹出现。当图像放大时,类似于 CV_INTER_NN 方法*/

    cvResize(image, resize3, CV_INTER_AREA);

    /*立方插值*/

    cvResize(image, resize4, CV_INTER_CUBIC);

    /*在8*8的邻域内的Lanczos插值*/

    cvResize(image, resize5, CV_INTER_LANCZOS4);



    cvShowImage("CV_INTER_NN", resize1);

    cvShowImage("CV_INTER_LINEAR", resize2);

    cvShowImage("CV_INTER_AREA", resize3);

    cvShowImage("CV_INTER_CUBIC", resize4);

    cvShowImage("CV_INTER_LANCZOS4", resize5);



    cvWaitKey(0);



    cvReleaseImage(&resize1);

    cvReleaseImage(&resize2);

    cvReleaseImage(&resize3);

    cvReleaseImage(&resize4);

    cvReleaseImage(&resize5);

    cvDestroyAllWindows();

    cvReleaseImage(&image);

    return 0;

}
View Code

 

你可能感兴趣的:(opencv)