What do fspecial image filtering parameters mean?

3 views (last 30 days)
I would like to high-pass-filter an image to get rid of wavelengths longer than about 30 pixels. Here is what I am trying:
hpFiltImage = myImage - imfilter(myImage,fspecial('gaussian',hsize,sigma));
I do not have an intuition for the units or meaning of hsize and sigma. How do I choose hsize and sigma to get the desired cutoff wavelength of 30 pixels?

Accepted Answer

David Young
David Young on 9 Sep 2014
The Gaussian filter does not have a sharp cut-off, but 2*pi*sigma is the wavelength at which the amplitude is multiplied by a factor of about 0.6 (more exactly, exp(-0.5)). So you might set sigma to 30/(2*pi) to suppress wavelengths over about 30 pixels.
hsize needs to be big enough that you don't truncate the filter too much. I use hsize = 2*ceil(2.6*sigma)+1 which gives roughly 1% truncation error on each dimension of the image, but you may wish to vary this depending on the trade-off between precision and compute time for your problem.
  1 Comment
Chad Greene
Chad Greene on 9 Sep 2014
David, thank you so much for this clear explanation. It all makes sense now.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!