找到图像的3x3窗口,并用整个图像的中心像素替换平均值

时间:2016-08-30 09:14:46

标签: c++ opencv windowing

我只想取一个图像的3x3邻居窗口并用中心像素替换平均值并计算其平均值,方差,熵以在c ++ opencv中制作特征向量我做错了请建议我需要这些功能分类

cv::Mat ppa::find_win(cv::Mat wav, int win_size){     // 

wav.convertTo(wav, CV_64F);                        // convert intto float
Mat varMap = Mat::zeros(wav.rows,wav.cols,wav.type());         // padding to avoid extra pixels 
int border = ceil(win_size/2);                   // round off border
for(int i=border;i<=wav.rows-border-1;i++)
{
    for(int j=border;j<=wav.cols-border-1;j++)
    {
        Rect win; 
//      cout<<i<<" "<< j<<endl;
        win.x = j-border; win.y = i-border;
        win.width = win_size;win.height = win_size;
        cv ::Mat window = wav(win);         // return the window of the 

        cv::Mat win1;
        window.copyTo(win1);

        cv:Scalar tempVal = mean(win1);
        float myMAtMean = tempVal.val[0];
        win1.at<double>(i,j) = myMAtMean;       /// replaced central pixel with mean value of neighbor pixel

        //............................ calculate mean var of the  returned windows.......................................
        cv::transpose(window,window);
        window.convertTo(window, CV_64F);
        arma::mat Ig_arma( reinterpret_cast<double*>(window.data), window.cols, window.rows );

        arma::mat mn = arma::mean(Ig_arma);     //
        arma::mat vr = var(Ig_arma);             // varience                
        double en = calculateEnergy(Ig_arma);    // energy
    }   
}
return win1;
}

0 个答案:

没有答案
相关问题