void Lee(Mat &src, Mat &dst) { for( int i = (n-1)/2; i < src.rows-(n-1)/2; ++i) for( int j = (n-1)/2; j < src.cols-(n-1)/2 ; ++j ) { int temp=( src.at<uchar>(i,j) +src.at<uchar>(i-1,j-1) +src.at<uchar>(i-1,j) +src.at<uchar>(i,j-1) +src.at<uchar>(i+1,j) +src.at<uchar>(i,j+1) +src.at<uchar>(i+1,j+1) +src.at<uchar>(i-1,j+1) +src.at<uchar>(i+1,j-1) )/9; int temp_devation=sqrt((double) ((src.at<uchar>(i,j)-k)*(src.at<uchar>(i,j)-k) +(src.at<uchar>(i-1,j-1)-k)*(src.at<uchar>(i-1,j-1)-k) +(src.at<uchar>(i-1,j)-k)*(src.at<uchar>(i-1,j)-k) +(src.at<uchar>(i,j-1)-k)*(src.at<uchar>(i,j-1)-k) +(src.at<uchar>(i+1,j)-k)*(src.at<uchar>(i+1,j)-k) +(src.at<uchar>(i,j+1)-k)*(src.at<uchar>(i,j+1)-k) +(src.at<uchar>(i+1,j+1)-k)*(src.at<uchar>(i+1,j+1)-k) +(src.at<uchar>(i-1,j+1)-k)*(src.at<uchar>(i-1,j+1)-k) +(src.at<uchar>(i+1,j-1)-k)*(src.at<uchar>(i+1,j-1)-k))/9); double w=1-(temp_devation*temp_devation)/(d*d); dst.at<uchar>(i,j)=temp+w*(k-temp); } }
int mean(Mat &src) { Mat_<Vec3b> _src = src; int temp_mean=0; for( int i=0; i<src.rows;++i) for( int j=0; j<src.cols;++j) { temp_mean+=_src(i,j)[0]; } temp_mean=temp_mean/(src.rows*src.cols); return temp_mean; } int deviation(Mat &src, int n) { Mat_<Vec3b> _src = src; double temp_deviation=0; for( int i=0; i<src.rows;++i) for( int j=0; j<src.cols;++j) { temp_deviation+=(_src(i,j)[0]-n)*(_src(i,j)[0]-n); } temp_deviation=temp_deviation/(src.rows*src.cols); temp_deviation=sqrt(temp_deviation); return (int)temp_deviation; }