Search code examples
matlabimage-processingfilteringgeometric-mean

Geometric mean filter for denoising image in MATLAB


I am new to MATLAB. I don't know how to use geometric mean filter for filtering noisy image. For arithmetic mean filter I use this:

H = fspecial('average',5);
a = imfilter(a, H);

Is there any similar way for geometric mean filter?


Solution

  • Yes there is. I suggest reading both the Wikipedia page about geometric mean as well as this blog by Steve Eddins who works at The Mathworks.

    To borrow Steve's explanation (and whole code/example actually):

    The local geometric mean filter multiplies together all the pixel values in the neighborhood and then takes the N-th root, where N is the number of pixels in the neighborhood.

    So in terms of Matlab code, with h being the kernel filled with ones having size of the neighborhood you use to compute the average and I being your image:

    geo_mean = imfilter(log(I), h, 'replicate');
    geo_mean = exp(geo_mean);
    geo_mean = geo_mean .^ (1/numel(h));
    

    Hope that helps!