Gaussian gradient vs derivative

4 Ansichten (letzte 30 Tage)
Marcus D.
Marcus D. am 5 Jun. 2015
Kommentiert: Marcus D. am 6 Jun. 2015
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 Kommentare
David Young
David Young am 6 Jun. 2015
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.
Marcus D. am 6 Jun. 2015
Thank you!

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by