Search code examples
matlabimage-processingfilteringconvolutiongaussian

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.


Solution

  • 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'...)