• LEE滤波C++算法(结合opencv)


    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;
    }
    
    
    
     
  • 相关阅读:
    MongoDB
    新公司管理经营
    剪辑理论
    色彩理论
    商业模式
    电影手法
    [好文转载] 每个程序员都应该学习使用Python或Ruby
    File类递归
    【CF1447】div2复盘
    【心得体会】11.9-11.15
  • 原文地址:https://www.cnblogs.com/chchche/p/2815303.html
Copyright © 2020-2023  润新知