Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asymmetric Gaussian Filter - Different Size and STD for Horizontal and Vertical Filters

I now want to use asymmetric Gaussian filter kernel to smooth an image using MATLAB, because I don't want the equal smoothness in vertical and horizontal(with different size of Gaussian mode and different standard deviation). But I cannot find a system function to do this job. It seems that the function fspecial() doesn't support this.

So, how can I implement this filter?

Thanks a lot.

like image 572
XiaJun Avatar asked Mar 06 '13 03:03

XiaJun


3 Answers

You can apply horizontal and vertical filtering separately.

v = fspecial( 'gaussian', [11 1], 5 ); % vertical filter
h = fspecial( 'gaussian', [1 5], 2 ); % horizontal
img = imfilter( imfilter( img, h, 'symmetric' ), v, 'symmetric' );

Moreover, you can "compose" the two filters using an outer product

f = v * h; % this is NOT a dot product - this returns a matrix!
img = imfilter( img, f, 'symmetric' );

PS
if you are looking for a directional filtering, you might want to consider fspecial('motion'...)

like image 174
Shai Avatar answered Sep 23 '22 17:09

Shai


You can use fspecial with a twist, for example:

 H= fspecial('gaussian',15,2) ;
 H2=imresize(H,[1.5*size(H,1) size(H,2)]);
 Img=conv2(Img,H2,'same');

Using imresize on the filter allows to control the x vs y axis asymmetry of the gaussian. Similarly you can use any type of image transformation (see imtransform) you can imagine to skew stretch etc...

like image 37
bla Avatar answered Sep 23 '22 17:09

bla


You can approximate a Gaussian filter by applying a Box filter multiple times. Since the Gaussian is separable, you can do this separately in both dimensions. A box filter in one dimension is a simple average over a linear segment of pixels. I don't know anything about matlab but I assume it can do this. If matlab can do rectangular filters you wouldn't even need to separate it.

For more details about approximating a Gaussian see http://nghiaho.com/?p=1159

like image 22
Mark Ransom Avatar answered Sep 23 '22 17:09

Mark Ransom