Median Filter Generalization

    annotation


    This article talks about a unique filter, an article about which appeared in 1990: Maslov A.M., Sergeev V.V. Identification of a linear distorting system using rank signal processing // Computer Optics. - M., 1990. - Issue 6. - S.97-102. This algorithm is called the “Rank Processing Algorithm” and in fact is a generalization of the median filter.
    The use of this filter is justified in two cases - to suppress noise and to reduce grease.
    image
    Figure 1 - the original image, 2 - blurry and noisy salt.


    Signal Processing Algorithm - Extreme Filter


    The algorithm consists in processing the image by a local window with recording the result of processing in a new image:
    1. Let us be at the image point with coordinates (I, J) - current count
    2. Around the current reference, we consider a local neighborhood of size NxN
    3. Using the values ​​of points in a local neighborhood, a variational series is constructed , which we denote by p . The size of this row is N * N.
    4. In the resulting image, the current count takes on the following rule:

    image
    where k is the parameter of the algorithm, N is an odd number, Im1 is the original image, Im2 is the resulting image.
    If k = (N ^ 2 + 1) / 2 - that is, the center of the variational series - this filter becomes a known median filter. In the future, this parameter will be called indentation .

    Extreme Filter Properties


    The properties of this filter are very useful in practice, since the filter allows you to compensate not only for noise but to eliminate (partially) the effects of image blur. The limiting case of this filter at k = (N ^ 2 + 1) / 2 is a median filter that only eliminates noise but does not touch the border, and if the image is blurry, the blur will remain.

    At k <(N ^ 2 + 1) / 2, the noise is filtered slightly worse, but the image sharpness increases, and at k = 0, the noise is not filtered at all, but the grease will be eliminated in the strongest way.

    In order not to bother readers with an elementary implementation of this algorithm, I will provide here the code in Matlab.
    The testing script will read the image, blur it, and add noise. Then the image is restored by these extreme filters. Filter function code im2_rang_filter :
    1. I1 = imread('coins.png');
    2. h = ones(3,3) / 9;
    3. I2 = imfilter(I1,h) ;
    4. I3 = imnoise(I2,'salt & pepper',0.02);
    5. I4 = im2_rang_filter (I3, 1, 2);
    6.  
    7. figure; imagesc(I1);
    8. colormap gray;
    9. figure; imagesc(I3);
    10. colormap gray;
    11. figure; imagesc(I4)
    12. colormap gray;
    * This source code was highlighted with Source Code Highlighter.



    1. function outImage= im2_rang_filter (aImage, aHalfWindowSize, aOtsup)
    2. [ver,hor] = size(aImage);
    3. wsize = (aHalfWindowSize*2+1)^2;
    4. result = zeros(ver,hor);
    5. for i = aHalfWindowSize+1 : (ver - aHalfWindowSize)
    6.   for j = aHalfWindowSize+1 : (hor - aHalfWindowSize)
    7.     
    8.     wind = aImage((i-aHalfWindowSize) : (i + aHalfWindowSize), (j-aHalfWindowSize) : (j + aHalfWindowSize));
    9.     vec = reshape(wind,1,wsize);
    10.     vec = sort(vec);
    11.     
    12.     if (abs(vec(aOtsup+1) - aImage(i,j)) < abs(vec(wsize - aOtsup) - aImage(i,j)) )
    13.       result(i,j) = vec(aOtsup+1);
    14.     else result(i,j) = vec(wsize - aOtsup);
    15.     end;
    16.     
    17.   end;
    18. end;
    19. outImage = result;
    * This source code was highlighted with Source Code Highlighter.

    Experiments


    Shown below are the results of filtering with a 3 by 3 window by varying the parameter k = 1.2.5. The first picture is the original image, the second picture is distorted, followed by filtered ones at k = 1, 2, 5:
    Original:
    image
    Distorted:
    image
    Recovered at k = 1:
    image
    Recovered at k = 2:
    image
    Recovered at k = 5:
    image

    I have this I really like the filter and I actively use it in practice. Readers are interested in this filter.

    Also popular now: