Kuan滤波C++实现(结合opencv)
void Kuan(Mat &src, Mat &dst,int n) { 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=(double)(d*d)/(d*d+temp_devation*temp_devation); dst.at<uchar>(i,j)=temp+w*(k-temp); } }