matlab - gradient and derivative -
i trying find first derivative of gaussian image (using matlab) , tried 2 ways.one using gradient , 1 calculating derivative results different each other.
method 1 k=7,s=3% kernel,st.dev f = fspecial('gaussian', [k k], s) [gx,gy] = gradient(f) method 2 k=7,s=3% kernel,st.dev [x,y] = meshgrid(-floor(k/2):floor(k/2), -floor(k/2):floor(k/2)) g = exp(-(x.^2+y.^2)/(2*s^2))/(2*pi*(s^2)) gn=g/sum(g(:)) gx = -x.*gn/(s^2) gy = -y.*gn/(s^2) gx , gy should same 2 methods there difference in values. know why is? expecting same. there preferred way calculate derivative? thank you.
edit: changed g definition per conrad's suggestion problem still persists.
this looks wrong:
g = exp(-(x.^2+y.^2)/(2*s^2))/(2*pi*s); assuming supposed normal density (x,y) x , y independent 0 mean rv equal sds = s, should be:
g = exp(-(x.^2+y.^2)/(2*s^2))/(2*pi*(s^2)); (the term in front of exponential in each component 1/(sqrt(2*pi)*s) , have twice giving 1/(2*pi*s^2) )
Comments
Post a Comment