/*、1.方框濾波:boxFilter函數(注:均值濾波是歸一化后的方框濾波)*/
/*函數原型: void boxFilter(InputArray src, OutputArray dst, int ddepth,Size ksize,Point anchor=Point(-1,-1),boolnormalize=true,int boderType=BORDER_DEFAULT) */
/*參數詳解: InputArray src-----源圖像 OutputArray dst----目標圖像 int ddepth----輸出圖像深度,輸出圖像深度,“-1”代表使用原圖深度,即src.depth() Size ksize----內核的大小,寫法size(5x5),就表示5x5的內核大小 Point anchor-----表示錨點,默認值Point(-1,-1),坐標為負值,表示取核的中心 boolnormalize-----表示內核是否被其區域歸一化,默認值為true boderType----用於推斷圖像外部像素的某種邊界模式,默認值BORDER_DEFAULT*/
/************ 新建QT控制台程序 *************/ #include <QCoreApplication> #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <opencv2/imgproc/imgproc.hpp> #include <iostream>
using namespace std; using namespace cv; int main() { Mat srcImage=imread("Valley_logo.jpg");//讀入原圖
namedWindow("均值濾波[原圖]"); namedWindow("均值濾波[效果圖]"); imshow("均值濾波[原圖]",srcImage); //進行均值濾波操作
Mat dstImage; boxFilter(srcImage,dstImage,-1,Size(5,5)); //顯示效果圖
imshow("均值濾波[效果圖]",dstImage); waitKey(0); return 0; }
運行結果如下:
原圖 5X5內核 3X3內核