Last edited on 1999-03-15 10:57:37 by stolfi

The weighted rank filter

The basic idea

A rank filter (RF) is an image processing algorithm that replaces each pixel p by its rank relative to the pixels in some neighborhood of p. Thus if p is the brightest pixel in its neighborhood, it is mapped to white; if it is the darkest, it is mapped to black; and if it is the median, it is mapped to 50% gray.

A rank filter can also be described as applying to each pixel an histogram equalization mapping, where the histogram is restricted to the pixel's neighborhood. Indeed the basic RF is is usually called local histogram equalization in the literature.

A rank filter rejects most of the intensity variations with scale greater than the window size, while amplifying those with smaller scales. It is therefore basically a high-pass filter. Very loosely, it can be viewed as a "complement" of the well-known median filter.

Note that the RF is quite non-linear. Compared to linear high-pass filters, it has the advantage of being morphological, in the sense that its output is not affected by arbitrary monotonic mapping of the intensity values. It is therefore useful in restoring the contrast of images that have been overexposed, underexposed, or badly corrected; especially images that have been degraded by a photograpic or process whose parameters vary (not too fast) from pixel to pixel.

The weighted rank filter

The basic RF described above has one drawback: an isolated bright or dark spot surrounded by a contrasting background will produce an "echo" whose shape is that of the window.

We can avoid such defects by using a weighted rank filter (WRF): a variant of the basic rank filter, in which the neighbors are weighted according to distance, and the rank computation takes such weights into account. More precisely, the rank of a pixel p is redefined as the sum of the weights of the neighbors of p which are darker than p, divided by the sum of all neighbor weights.

A suitable weight function is the 2-D Gaussian distribution

w[x,y] = exp(-(x^2+y^2)/r^2)

The characteristic radius r defines the effective size of the neighborhood.

Examples

The figure below shows a sample image (top left) and the results of Gaussian WRF's with r = 2, 4, 6, 8, 12.

input image
r = 2
r = 4
r = 6
r = 8
r = 12