Hi all , when i try to write gaussian gradient diection.I find some problem in the loop to calcuate antan2.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)));
}