(代码5)图像平滑处理

11 篇文章 0 订阅
#include "cv.h"
#include "highgui.h"
 
void example2_4( IplImage* image )
{
    // Create some windows to show the input
    // and output images in.
    //
    cvNamedWindow( "Example2_4-in", CV_WINDOW_AUTOSIZE );
    cvNamedWindow( "Example2_4-out", CV_WINDOW_AUTOSIZE );
     
    // Create a window to show our input image
    //
    cvShowImage( "Example2_4-in", image );
     
    // Create an image to hold the smoothed output
    //
    IplImage* out = cvCreateImage(
        cvGetSize(image),
        IPL_DEPTH_8U,
        3
    );
     
    // Do the smoothing
    //
    cvSmooth( image, out, CV_GAUSSIAN, 5,5 );
    cvSmooth( out, out, CV_GAUSSIAN, 5, 5);
     
    // Show the smoothed image in the output window
    //
    cvShowImage( "Example2_4-out", out );
     
    // Be tidy
    //
    cvReleaseImage( &out );
 
    // Wait for the user to hit a key, then clean up the windows
    //
    cvWaitKey( 0 ); 
    cvDestroyWindow("Example2_4-in" );
    cvDestroyWindow("Example2_4-out" );
     
}
 
int main( int argc, char** argv )
{
  IplImage* img = cvLoadImage( "lena.jpg" );
  cvNamedWindow("Example1", CV_WINDOW_AUTOSIZE );
  cvShowImage("Example1", img );
  example2_4( img );
//  cvWaitKey(0);
  cvReleaseImage( &img );
  cvDestroyWindow("Example1");
}
 
/*
Smooth
各种方法的图像平滑
void cvSmooth( const CvArr* src, CvArr* dst,
               int smoothtype=CV_GAUSSIAN,
               int param1=3, int param2=0, double param3=0, double param4=0 );
src
输入图像.
dst
输出图像.
smoothtype
平滑方法:
CV_BLUR_NO_SCALE (简单不带尺度变换的模糊) - 对每个象素的 param1×param2 领域求和。如果邻域大小是变化的,可以事先利用函数 cvIntegral 计算积分图像。
CV_BLUR (simple blur) - 对每个象素param1×param2邻域 求和并做尺度变换 1/(param1•param2).
CV_GAUSSIAN (gaussian blur) - 对图像进行核大小为 param1×param2 的高斯卷积
CV_MEDIAN (median blur) - 对图像进行核大小为param1×param1 的中值滤波 (i.e. 邻域是方的).
CV_BILATERAL (双向滤波) - 应用双向 3x3 滤波,彩色 sigma=param1,空间 sigma=param2. 关于双向滤波,可参考 http://www.dai.ed.ac.uk/CVonline/LOCAL_COPIES/MANDUCHI1/Bilateral_Filtering.html
param1
平滑操作的第一个参数.
param2
平滑操作的第二个参数. 对于简单/非尺度变换的高斯模糊的情况,如果param2的值 为零,则表示其被设定为param1。
param3
对应高斯参数的 Gaussian sigma (标准差). 如果为零,则标准差由下面的核尺寸计算:
sigma = (n/2 - 1)*0.3 + 0.8, 其中 n=param1 对应水平核,
                                 n=param2 对应垂直核.
*/


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值