Asymmetric Gauss filter - different size and standard deviation for horizontal and vertical filters

Now I want to use the core of the asymmetric Gaussian filter to smooth the image using MATLAB, because I do not want equal vertical and horizontal smoothness ( with a different size of the Gaussian mode and a different standard deviation ). But I can not find the system function for this work. It seems that the fspecial() function does not support this.

So how can I implement this filter?

Thank you very much.

+4
source share
4 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' ); 

In addition, you can β€œcompose” two filters using an external 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 directional filtering you might consider fspecial('motion'...)

+7
source

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 you to control the asymmetry of the x vs y Gaussian axis. Similarly, you can use any type of image transformation (see imtransform ) that you can imagine to skew stretching, etc.

+5
source

You can approximate a Gaussian filter by applying the Box filter several times. Since it is Gaussian separable, you can do it separately in both dimensions. The filter box in one dimension is a simple average of the linear segment of pixels. I don't know anything about Matlab, but I guess he can do it. If Matlab can create rectangular filters, you won’t even have to split it.

For more information on the Gaussian approximation, see http://nghiaho.com/?p=1159

+3
source

You can use the MATLAB conv2() function, which supports separable filters, and also faster than imfilter() .

So it will be something like:

 v = fspecial( 'gaussian', [11 1], 5 ); % vertical filter h = fspecial( 'gaussian', [1 5], 2 ); % horizontal mO = conv2(v, h, mI); 

Where mI is the input image and mO is the output.

0
source

All Articles