MATLAB Answers

Gaussian filters returned by fspecial() with asymmetric size parameter

3 views (last 30 days)
DGM on 22 Jul 2020
Edited: DGM on 22 Jul 2020
I noticed some edge artifacts in images I had filtered using a filter from fspecial, so I decided to take a look at the filter shape itself.
sz=[150 400]; % make it big enough to see at 1:1 display
% just normalize it so it's human-visible
The cropped edges explains why there were edge displacement artifacts in the filtered image. Certainly, the documentation clearly says it's supposed to be a rotationally symmetric gaussian, but for some reason, I had been expecting something more like this when given an asymmetric size parameter:
% generate an asymmetric gaussian filter using similar parameters
[xx yy]=meshgrid(1:szf(2),1:szf(1));
r=sqrt(((xx-ceil(szf(2)/2))/(szf(2)/2)).^2 + ((yy-ceil(szf(1)/2))/(szf(1)/2)).^2);
% just normalize it so it's human-visible
Which again, I shouldn't really have expected given the documentation. My question is more of a conceptual/usage question then. I can understand the case when HSIZE is symmetric, but handling asymmetry by cropping instead of reshaping seems counterintuitive to me. I assume that the behavior of fspecial() is not without purpose. What are good reasons/applications for an asymmetrically cropped round filter like fspecial produces? My initial assumption would be that the strong edge step defeats some of the benefits of using a gaussian, but maybe there are good reasons for technical applications that I don't understand. On the other hand, are there cases where my second example would be preferred or disfavored? I feel like I'm missing something important.


Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!