MATLAB Answers

Gaussian filters returned by fspecial() with asymmetric size parameter

3 views (last 30 days)
DGM
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.
alph=0.3;
sz=[150 400]; % make it big enough to see at 1:1 display
aa=fspecial('gaussian',sz+1,alph*max(sz)/2);
% just normalize it so it's human-visible
aa=imlnc(aa,'independent','tol',1E-6);
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
szf=floor(sz/2)*2+1;
[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);
r(r>1)=1;
bb=exp(-(r/(1.414*alph)).^2);
bb=bb/sum(bb(:));
% just normalize it so it's human-visible
bb=imlnc(bb,'independent','tol',1E-6);
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.

  0 Comments

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!