Gaussian gradient vs derivative
이전 댓글 표시
I am trying to find the edges of an image using the derivative of a Gaussian.I tried two ways: the one using the gradient and one calculating the derivative but the results look different from each other.
1: Gradient of filter
w=7,sd=3% window,st.dev
f = fspecial('gaussian', [w w], sd);
[Gx,Gy] = gradient(f);
2: Derivative of Gaussian
w=7,sd=3% window,st.dev
[x,y] = meshgrid(-floor(w/2):floor(w/2), -floor(w/2):floor(w/2));
G = exp(-(x.^2+y.^2)/(2*sd^2))/(2*pi*(sd^2));
G_norm=G/sum(G(:));
Gx = -x.*G_norm/(sd^2);
Gy = -y.*G_nrom/(sd^2)
I was expecting Gx and Gy to be the same in the two methods but it is not. I have two questions: 1.Why don't these two methods give the same result? 2.Is there a preferred way from these two (or a completely different one) to create the Gaussian derivative mask for edge detection? Thank you in advance.
Edit: For the first method I find Gx =
0.0058 0.0040 0 -0.0040 -0.0058
0.0068 0.0047 0 -0.0047 -0.0068
0.0072 0.0049 0 -0.0049 -0.0072
0.0068 0.0047 0 -0.0047 -0.0068
0.0058 0.0040 0 -0.0040 -0.0058
For the second method i find Gx =
0.0071 0.0042 0 -0.0042 -0.0071
0.0083 0.0049 0 -0.0049 -0.0083
0.0088 0.0052 0 -0.0052 -0.0088
0.0083 0.0049 0 -0.0049 -0.0083
0.0071 0.0042 0 -0.0042 -0.0071
댓글 수: 9
Image Analyst
2015년 6월 6일
What is your image variable? Where does it come into play in this code?
Marcus D.
2015년 6월 6일
Image Analyst
2015년 6월 6일
Why not use imgradient()? I'm having trouble following what you're doing. Why not just use imfilter or conv2 with G itself? Why are you multiplying x by G?
Marcus D.
2015년 6월 6일
Image Analyst
2015년 6월 6일
Why not use imgradient()?
Or, if you want a DOG filter, see the attached demo.
David Young
2015년 6월 6일
Alternatively, for a function that computes the x and y components of the gradient rather than magnitude and direction, and which has some additional options, see my fex submission.
Your two ways of getting the derivative of a filter should be roughly equivalent if you have implemented them correctly. If there are small differences, it's because the finite differencing done by gradient is only an approximation to the analytical derivative. If there are large differences, it's because you have made a mistake in the implementation. Can you say what the nature of the differences is?
Marcus D.
2015년 6월 6일
David Young
2015년 6월 6일
I think the differences are simply due to approximating the derivative by finite differences in your first method. It will not make a big difference which you use; I guess the second method is a little more accurate. I don't know a better method.
Marcus D.
2015년 6월 6일
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Image Category Classification에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!