Posts Tagged ‘Gaussian’

## Efficient algorithms vs efficient code

Saturday, October 21st, 2017

Since I have spent quite a bit of time porting 25-year old code, I have been confronted with the significant changes to CPU architecture over that time. Code in DIPlib used to be very efficient back then, but some optimizations did not age well at all. I want to show some examples here. It is nice to see that a little bit of effort into optimization can go a long way.

I also want to give a quick example of a highly optimized implementation of an inefficient algorithm, which highlights the difference between algorithms and code.

## No, that’s not a Gaussian filter

Friday, February 6th, 2015

I recently got a question from a reader regarding Gaussian filtering, in which he says:

I have seen some codes use 3×3 Gaussian kernel like

`    h1 = [1, 2, 1]/4`

to do the separate filtering.

The paper by Burt and Adelson (The Laplacian Pyramid as a Compact Image Code, IEEE Transactions on Communication, 31:532-540, 1983) seems to use 5×5 Gaussian kernel like

`    h1 = [1/4 - a/2, 1/4, a, 1/4, 1/4-a/2]`,

and `a` is between 0.3-0.6. A typical value of `a` may be 0.375, thus the Gaussian kernel is:

`    h1 = [0.0625, 0.25, 0.375, 0.25, 0.0625]`

or

`    h1 = [1, 4, 6, 4, 1]/16`.

I have written previously about Gaussian filtering, but neither of those posts make it clear what a Gaussian filter kernel looks like.

## Gaussian filtering with the Image Processing Toolbox

Tuesday, October 6th, 2009

Edit May 2018: Since publishing this post, the MATLAB Image Processing Toolbox has added the function imgaussfilt that correctly applies a Gaussian smoothing filter. For Gaussian derivatives, the recommendations here still apply.

If you don’t use DIPimage, you probably use MATLAB’s Image Processing Toolbox. This toolbox makes it really easy to do convolutions with a Gaussian in the wrong way. On three accounts. The function fspecial is used to create a convolution kernel for a Gaussian filter. This kernel is 2D. That’s the first problem. The other two problems are given by the default values of its parameters. The default value for the kernel size is [3 3]. The default value for the σ (sigma) is 0.5. (more…)

## Gaussian filtering

Saturday, December 6th, 2008

In my recent lectures on filtering I was trying to convey only one thing to my students: do not use the uniform filter, use the Gaussian! The uniform (or “box”) filter is very easy to implement, and hence used often as a smoothing filter. But the uniform filter is a very poor choice for a smoothing filter, it simply does not suppress high frequencies strongly enough. And on top of that, it inverts some of the frequency bands that it is supposed to be suppressing (its Fourier transform has negative values). There really is no excuse ever to use a uniform filter, considering there is a very fine alternative that is very well behaved, perfectly isotropic, and separable: the Guassian. Sure, it’s not a perfect low-pass filter either, but it is as close as a spatial filter can get.

Because recently I found some (professionally written) code using Gaussian filtering in a rather awkward way, I realized even some seasoned image analysis professionals are not familiar and comfortable with Gaussian filtering. Hence this short tutorial.