|
On Oct 14, 8:50 pm, Jomar Bueyes <jomarbue...@hotmail.com> wrote:
> On Oct 14, 12:30 pm, Martin Alegre <tin.ale...@gmail.com> wrote:
>
>
>
>
>
>
>
>
>
> > Hi everyone,
>
> > I'm trying to create a first and a second derivatives of a 2D Gaussian
> > function, however the results seem not to be as expected. Could anyone
> > kindly have a look at it? I checked if I did the derivation correctly,
> > but it seems to be OK.
>
> > Cheers,
>
> > Tin
>
> > function g = gauss2d(sigmax, sigmay, order)
>
> > sigmax2 = sigmax * sigmax;
> > sigmay2 = sigmay * sigmay;
> > dx = floor(3.0*sigmax);
> > dy = floor(3.0*sigmay);
> > [X,Y] = meshgrid(-dx:dx,-dy:dy);
> > f = 1/sqrt(2*pi*sigmax*sigmay);
>
> > switch order
> > case 0
> > g = f * exp(-0.5 * ((X.^2/sigmax2)+(Y.^2/sigmay2)));
> > case 1
> > g = f * (- (X.^2*sigmay2 + Y.^2*sigmax2)/
> > (sigmax2*sigmay2) ) * exp(-0.5 * ((X.^2/sigmax2)+(Y.^2/sigmay2)));
> > case 2
> > g = f * ((X.^2 + Y.^2 - 2 * sigmax*sigmay)/
> > (sigmax2*sigmay2)) * exp(-0.5 * ((X.^2/sigmax2)+(Y.^2/sigmay2)));
> > end
>
> > g = g ./ sum(sum(abs(g)));
> > end
>
> Martin,
>
> When you write "the results seem not to be as expected", what was the
> expected result?
>
> Besides that, because you are dealing with a function of two
> variables, the function has two first-order partial derivatives. One
> with respect to each variable. Likewise, the function has three second
> order partial derivatives. One with respect to x twice, one with
> respect to y twice, and one with respect to x and then to y or vice
> versa. Check you assignment make sure you understand what is being
> asked.
>
> Also, the last statement before the end of the function can be written
> as
>
> g = g/sum(abs(g(:));
>
> 1) g(:) is treated as a one-dimensional array thus obviating the need
> for nested 'sum' functions.
> 2) No need for the ./ operator because the denominator is a scalar
>
> HTH
>
> Jomar
Hi Jomar,
Thanks for your reply
> When you write "the results seem not to be as expected", what was the
> expected result?
I was refering to the visual result. I'm studying Gaussian derivative
filters by my own. So, it's not for an assignment.
I wanted to reproduce some plots that I found in the following 2
webpages:
http://fourier.eng.hmc.edu/e161/lectures/gradient/node10.html (there's
a 2D plot for the Laplacian of Gaussian)
http://homepages.inf.ed.ac.uk/rbf/CVonline/LOCAL_COPIES/OWENS/LECT6/node2.html
There's a subsection "Second order derivative operators" and again
there are 2D plots for Gaussian derivatives.
Best,
Tin
|