Ask Your Question
0

Why can not show full image when i use fastatan2?

asked 2014-03-16 21:51:54 -0600

wuling gravatar image

updated 2014-03-17 08:49:48 -0600

Hi all , when i try to write gaussian gradient diection.I find some problem in the loop to calcuate dst.The variable dst1 & dst2 can show full image ,but the variable dst can not show full image.I don't know what happens. I am very confused.Could you tell mell what's wrong.Thanks your advance.

     int KernelSize=5;
    int n=int(KernelSize/2);
     vector<float>  dx;
    vector<float> dy;

    for (int i = -n; i <= n; ++i)
    {
        dx.push_back(g1(i, sigma));
        dy.push_back(g1(i, sigma));
    }

    normalize(dx);
    normalize(dy);
    Mat kx=Mat(dx);
    Mat ky=Mat(dy);
    vector<float> kc;
    kc.push_back(0.0);
    kc.push_back(0.0);
    kc.push_back(1.0);
    kc.push_back(0.0);
    kc.push_back(0.0);
    Mat k=Mat(kc);

     Mat temp1;
     Mat temp2;
     Mat dst1,dst2;
     cv::sepFilter2D(src,temp1,CV_32FC1,kx,kc);
     cv::sepFilter2D(src,temp2,CV_32FC1,kc,ky);
       cv::normalize(temp1,dst1, 0x00, 0xFF, cv::NORM_MINMAX, CV_8U);
      imshow("temp1",dst1);
      cv::normalize(temp2,dst2, 0x00, 0xFF, cv::NORM_MINMAX, CV_8U);
      imshow("temp2",dst2);
      Mat temp=cv::Mat::zeros(src.rows, src.cols, CV_32FC1);

      for(int y=0;y<temp1.rows;y++)
      {
           for(int x=0;x<temp1.cols;x++)
           {
               float a=(float)temp2.at<float>(y,x);
               float b=(float)temp1.at<float>(y,x);
              temp.at<float>(y,x)=cv::fastAtan2(a,b);
           }
      }

    cv::normalize(temp,dst, 0x00, 0xFF, cv::NORM_MINMAX, CV_8U);

    where g1 is:
    float g1(const int &i, const float &sigma)
{
  return (float)(-(float)i / (sigma * sigma)
    * exp(-(float)(i * i) / (2.0 * sigma * sigma)));
}

& normalize:

    void normalize(vector<float> &kernel)
    {
      float f=0.0;
      for(int i=0;i<kernel.size();i++)
      {
         f+=fabs(kernel[i]);
      }
       if(f>0)
      {
         for(int i=0;i<kernel.size();i++)
         {
           kernel[i]/=f;
          }
      }

   }

NG.png

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2014-03-17 03:27:31 -0600

It is strange to me since I have not found any problem when running your code with VS 2012, OpenCV 2.4.8 (prebuilt version). You can see the result in the attach image file.image description

edit flag offensive delete link more

Comments

Nice,But in my computer can not show thrid full image.Why?? I use 2.4.8 and VS2010

wuling gravatar imagewuling ( 2014-03-17 06:45:40 -0600 )edit

I have no idea why but I built the program in Release mode. Additionally, instead of writing:

cv::normalize(temp2,dst2, 0x00, 0xFF, cv::NORM_MINMAX, CV_8U);

you can write:

cv::normalize(temp2,dst2, 0, 255, cv::NORM_MINMAX, CV_8U);

as it has the same meaning but easier to understand the code.

tuannhtn gravatar imagetuannhtn ( 2014-03-17 07:29:04 -0600 )edit

Dear Tuannhtn, Thank,you chek this program.I change cv::normalize(temp2,dst2, 0, 255, cv::NORM_MINMAX, CV_8U); but it's the same.It's too bad for me. Maybe i should change VS2012 and try again.

wuling gravatar imagewuling ( 2014-03-17 09:01:27 -0600 )edit

Question Tools

Stats

Asked: 2014-03-16 21:51:54 -0600

Seen: 1,865 times

Last updated: Mar 17 '14