【学习OpenCV】——2.4对图像进行平滑处理

作者基于WIN10+VS2015+OpenCV3.0.0
(本人在学习的时候参考了xiahouzuoxin 的有关文章,在此感谢 )
图像平滑与图像模糊是同一概念,主要用于图像的去噪。平滑要使用滤波器,为不改变图像的相位信息,一般使用线性滤波,本文举例双边滤波,中值滤波和高斯滤波。只需调用库函数即可。效果在下文贴出。

例程如下 

#include"cv.h"
#include"highgui.h"
//void example2_4(IplImage*image)
int main(int argc, char**argv)
{
IplImage*image = cvLoadImage(argv[1]);
//Create some windows to show the input
//and output images in
//创建一个输入和输出图像
cvNamedWindow("Example4-in");
cvNamedWindow("Example4-out");
//Create a window to show our input image
//创建一个窗口显示我们的输入图像
cvShowImage("Example4-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_BILATERAL, 3, 3); 
//Show the smoothed image in the output window
//在输出窗口中显示平滑的图像
cvShowImage("Example4-out", out);
//Be tidy
//要整洁
cvReleaseImage(&out);
//Wait for the user to hit a key,then clean up the windows
//等待用户敲击按键,然后关闭窗口
cvWaitKey(0);
cvDestroyWindow("Example4-in");
cvDestroyWindow("Example4-out");
}

PS:百度翻译直接翻译的,大致对,个别地方别介意。
CV_BILATERAL  双边滤波
CV_MEDIAN  中值滤波
CV_GAUSSIAN  高斯滤波
直接替换即可。

效果:
(左边为原图像,右边为平滑处理过的图像)
1.双边滤波
【学习OpenCV】——2.4对图像进行平滑处理 - 晨晨晨阿晨 - 直行
 
2.中值滤波
【学习OpenCV】——2.4对图像进行平滑处理 - 晨晨晨阿晨 - 直行
 
3.高斯滤波
【学习OpenCV】——2.4对图像进行平滑处理 - 晨晨晨阿晨 - 直行
 
原文地址:https://www.cnblogs.com/yueqiuchen/p/6642003.html