Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Derivative of Gaussian filter in Matlab

Tags:

filter

matlab

Is there a derivative of Gaussian filter function in Matlab? Would it be proper to convolve the Gaussian filter with [1 0 -1] to obtain the result?

like image 849
cerebrou Avatar asked Jun 01 '14 12:06

cerebrou


2 Answers

As far as I know there is no built in derivative of Gaussian filter. You can very easily create one for yourself as follow:

For 2D

G1=fspecial('gauss',[round(k*sigma), round(k*sigma)], sigma);
[Gx,Gy] = gradient(G1);   
[Gxx,Gxy] = gradient(Gx);
[Gyx,Gyy] = gradient(Gy);

Where k determine the size of it (depends to which extent you want support).

For 1D is the same, but you don't have two gradient directions, just one. Also you would create the gaussian filter in another way and I assume you already have your preferred method.

Here I gave you up to second order, but you can see the pattern here to proceed to further orders.

The convolving filter you posted ( [1 0 -1] ) looks like finite difference. Although yours I believe is conceptually right, the most correct and common way to do it is with [1 -1] or [-1 1], with that 0 in the middle you skip the central sample in approximating the derivative. This may work as well (but bare in mind that is an approximation that for higher orders diverge from true result), but I usually prefer the method I posted above.


Note: If you are indeed interested in 2D filters, Derivative of Gaussian family has the steerability property, meaning that you can easily create a filter for a Derivative of Gaussian in any direction from the one I gave you up. Supposing the direction you want is defined as

cos(theta), sin(theta)

Then the derivative of Gaussian in that direction is

Gtheta = cos(theta)*Gx + sin(theta)*Gy

If you reapply this recursively you can go to any order you like.

like image 107
cifz Avatar answered Oct 15 '22 10:10

cifz


Of just use the derivative of a gaussian which is not more difficult then computing the gaussian itself.

G(x,y) = exp(-(x^2+y^2)/(2*s^2))
d/dx G(x, y) = -x/s^2 G(x,y)
d/dy G(x, y) = -y/s^2 G(x,y)
like image 27
Trilarion Avatar answered Oct 15 '22 11:10

Trilarion