杯具....写了个中值滤波器的函数编译没过...然后发现openCV里面有直接的函数...囧.. 自己写的中值率波函数,,应该没啥问题,RGB通道分别做一次: *#include<algorithm>
openCV的中值滤波函数
using namespace std; IplImage* CDrawDlg::MiddleProssing(IplImage* img,IplImage* img1) { int i,j,k,t; int move[8][2]={{0,1},{1,0},{-1,0},{0,-1},{1,1},{-1,-1},{1,-1},{-1,1}}; int p[9]; IplImage* tmp= detectanddraw(img); IplImage* tmp1=detectanddraw(img1); for(i=1;i<tmp->height-1;i++) { for(j=1;j<tmp->width-1;j++) { for(t=0;t<3;t++) { int ii=i; int jj=j; p[8]=((uchar*)(img->imageData + img->widthStep*jj))[ii*3+t]; for(k=0;k<8;k++) { ii=i+move[k][0]; jj=j+move[k][1]; p[k]=((uchar*)(img->imageData + img->widthStep*jj))[ii*3+t]; } sort(p,p+9); ((uchar*)(img1->imageData + img1->widthStep*j))[i*3+t]=p[4]; } } } return img1; } cvSmooth,其函数声明为: cvSmooth( const void* srcarr, void* dstarr, int smoothtype,int param1, int param2, double param3 ) cvSmooth函数的作用是对图象做各种方法的图象平滑。其中,srcarr为输入图象;dstarr为输出图象;param1为平滑操作的{dy}个 参数;param2为平滑操作的第二个参数(如果param2值为0,则表示它被设为param1);param3是对应高斯参数的标准差。 参数smoothtype是图象平滑的方法选择,主要的平滑方法有以下五种: CV_BLUR_NO_SCALE:简单不带尺度变换的模糊,即对每个象素在 param1×param2领域求和。 CV_BLUR:对每个象素在param1×param2邻域求和并做尺度变换 1/(param1•param2)。 CV_GAUSSIAN:对图像进行核大小为param1×param2的高斯卷积。 CV_MEDIAN:对图像进行核大小为param1×param1 的中值滤波(邻域必须是方的)。 CV_BILATERAL:双向滤波,应用双向 3x3 滤波,彩色设置为param1,空间设置为param2。 |