Just a note: When playing with Matlab with 3D images (CT-scans), I noticed that when defining a filter as above by

h = fspecial(‘gaussian’,[1,2*cutoff+1],sigma)

it is generally faster and also more flexible to use

J = imfilter(I,h,’replicate’,’conv’);

J = imfilter(J,permute(h,[2,3,1]),’replicate’,’conv’);

J = imfilter(J,permute(h,[3,1,2]),’replicate’,’conv’);

instead of applying the convn() function in all three dimensions.

The problem with convn(), and respectively conv2(), is that the replication pattern at the boarders cannot be defined (it is automatically padded with 0). Matlab’s internal function imgaussfilt3() seems to peroform almost equally fast as the code above, I guess it separates the kernel too.

Cheers!

]]>The combination `(dh,dh)`

would be a 2nd order derivative, corresponding to ∂²/∂x∂y.

To get the magnitude of the gradient, you need to add the square of the two partial derivatives, which you cannot do with a single convolution (the convolution is always a linear operation, and squaring is a non-linear operation).

]]>Ok, so the goal was to find the derivative in only one direction.

So I then interpret the expression conv2(dh,h,img) as follows:

the derivative (of the Gaussian) along x and the pure Gaussian along y.

Consequently conv2(dh,h,img) yields:

the pure Gaussian along x and the derivative (of the Gaussian) along y.

Would it then be correct to say that conv2(dh,dh,img) yields:

the derivative along x plus the derivative along y, i.e. the magnitude of the gradient? ]]>

No, it is `(dh,h)`

for a derivative along the x-axis, and `(h,dh)`

for a derivative along the y-axis.

out = conv2(dh,dh,img,'same');

instead of:

out = conv2(dh,h,img,'same');

?

]]>A Gaussian kernel with sigma=0.5 pixels has too much power in the frequencies above the Nyquist frequency. These frequencies are aliased when sampling. That is, their power is assigned to frequencies under the Nyquist frequency, causing low-frequency signals to appear in the sampled signal that were never present in the original signal.

The Nyquist frequency is simply the highest frequency that can be represented by the sampled signal/image, and depends with a simple fraction on the sampling frequency. Thus, the closer together the pixels are, the more detail can be represented in the image.

A Gaussian kernel has an infinite number of frequencies, but frequencies above a certain value have *very* low power, and can be ignored. Depending on where exactly you place this threshold (how large an error you are willing to accept), you need a sampling frequency of about 1*sigma to 1/0.8*sigma. This translates to, when picking a fixed sampling grid, a minimum sigma of 0.8 to 1 the sampling spacing.

When you sample a Gaussian with a sigma of 0.5 pixels, the resulting sampled sigma does not have a Guassian shape, and does not present some of the beneficial properties of the Gaussian.

If you want to convolve with such a small Guassian, you should do this through the Fourier domain, or following the recipe of Rein van den Boomgaard (presented at Scale-Space 2001).

]]>You’ve made some useful points in this article. It might also be useful to know that two convolutions with Gaussian filters applied sequentially (or “in cascade” as they say) is equivalent to a single Gaussian convolution, with variances related as follows:

sigma_eq^2 = sigma_1^2 + sigma_2^2

]]>