Rank filtering

advertisement
Rank filtering ( non – linear filtering )
Date 07/15/04
Order filter are implemented by arranging the neighborhood pixels in order from smallest to largest gray level value and
using this ordering to select the “correct” value. The placement of the value within this ordered set is referred as the rank .
1. Given an N x N window W, the pixel values can be ordered , as follows
I 1  I 2  I 3  ....  I N 2
where I1….I3… I N 2 are intensity values.
2. Select a value from a particular position in the list to use as the new value for the pixel.
From noise image Rank filtering mask (7 x 7 ) rank 1
From noise image Rank filtering mask (7 x 7 ) rank 4
1. Median filtering
The main problem with local averaging operations is that they tend to blur edges in an image. An alternative approach is
to replace each pixel value with the median of the gray values in the local neighborhood of that pixel. Filters using this
technique are called median filters.
In order to perform median filtering in a neghborhod of a pixel [i.j]:
1. Sort the pixels into ascending order by gray level.
2. Select the value of the middle pixel as the new value for pixel [i.j]
110 110 114


Example … 100 104 04


 95 88 85 
{85, 88, 95, 100, 104, 104, 110, 110, 114}
The median filter selects 104.
The principal function of median filtering is to force points with distinct intensities to be more like their neighbors,
actually eliminating intensity a pikes that appear isolated in the area of the filter mask. This filters are excellent for
impulse type of noise.
1.1 How It Works
Like the mean filter, the median filter considers each pixel in the image in turn and looks at its nearby neighbors to decide
whether or not it is representative of its surroundings. Instead of simply replacing the pixel value with the mean of
neighboring pixel values, it replaces it with the median of those values. The median is calculated by first sorting all the
pixel values from the surrounding neighborhood into numerical order and then replacing the pixel being considered with
the middle pixel value. (If the neighborhood under consideration contains an even number of pixels, the average of the
two middle pixel values is used.)
1.2 Guidelines for Use
By calculating the median value of a neighborhood rather than the mean filter, the median filter has two main advantages
over the mean filter:
1. The median is a more robust average than the mean and so a single very unrepresentative pixel in a neighborhood
will not affect the median value significantly.
2. Since the median value must actually be the value of one of the pixels in the neighborhood, the median filter does
not create new unrealistic pixel values when the filter straddles a edge. For this reason the median filter is much
better at preserving sharp edges than the mean filter.
In general, the median filter allows a great deal of high spatial frequency detail to pass while remaining very effective at
removing noise on images where less than half of the pixels in a smoothing neighborhood have been effected. (As a
consequence of this, median filtering can be less effective at removing noise from images corrupted with Gaussian noise.)
One of the major problems with the median filter is that it is relatively expensive and complex to compute. To find the
median it is necessary to sort all the values in the neighborhood into numerical order and this is relatively slow, even with
fast sorting algorithms such as quick sort. The basic algorithm can, however, be enhanced somewhat for speed. A
common technique is to notice that when the neighborhood window is slid across the image, many of the pixels in the
window are the same from one step to the next, and the relative ordering of these with each other will obviously not have
changed.
If you don’t want to use sorting algorithm and alternative approach is to calculate the histogram of grey levels in a
neghbourhood and then search this histogram to find the median. The median will be the grey level at which the
cumulative frequency equals or exceeds half the neigbourhood size.
Mean Filter
Median Filter
2. Minimum and maximum filters (Conservative smoothing)
The maximum filter selects the largest value within of pixel values, whereas the minimum filter selects the smallest value.
Conservative smoothing is a noise reduction technique that derives its name from the fact that it employs a simple, fast
filtering algorithm that sacrifices noise suppression power in order to preserve the high spatial frequency detail (e.g. sharp
edges) in an image. It is explicitly designed to remove noise spikes --- i.e. isolated pixels of exceptionally low or high
pixel intensity (e.g. salt and pepper noise) and is, therefore, less effective at removing additive noise (e.g. Gaussian noise)
from an image.
2.1 How It Works
Like most noise filters, conservative smoothing operates on the assumption that noise has a high spatial frequency and,
therefore, can be attenuated by a local operation which makes each pixel's intensity roughly consistent with those of its
nearest neighbors. However, whereas mean filtering accomplishes this by averaging local intensities and median filtering
by a non-linear rank selection technique, conservative smoothing simply ensures that each pixel's intensity is bounded
within the range of intensities defined by its neighbors.
This is accomplished by a procedure which first finds the minimum and maximum intensity values of all the pixels within
a windowed region around the pixel in question. If the intensity of the central pixel lies within the intensity range spread
of its neighbors, it is passed on to the output image unchanged. However, if the central pixel intensity is greater than the
maximum value, it is set equal to the maximum value; if the central pixel intensity is less than the minimum value, it is set
equal to the minimum value. Figure 1 illustrates this idea.
Figure 1 Conservatively smoothing a local pixel neighborhood. The central pixel of this figure contains
an intensity spike (intensity value 150). In this case, conservative smoothing replaces it with the
maximum intensity value (127) selected amongst those of its 8 nearest neighbors.
If we compare the result of conservative smoothing on the image segment of Figure 1 with the result obtained by mean
filtering and median filtering, we see that it produces a more subtle effect than both the former (whose central pixel value
would become 125) and the latter (124). Furthermore, conservative smoothing is less corrupting at image edges than
either of these noise suppression filters.
Minimum filtering ( mask size =3 x 3)
Minimum filtering causes the darker regions of an image
to swell in size and dominate the lighter regions ( mask
size =7 x 7)
Result from Maximum filtering with mask (3 x 3)
Result from Maximum filtering with mask (7 x 7)
Range filter
The range filter simply outputs the difference between the maximum and minimum grey levels in a neighborhood
centered pixel. This is non-linear edge detector.
3. Hybrid filters
Midpoint and alpha-trimmed mean filter. They are hybrid because they rely on ordering the pixel values , but they are
then calculated by an averaging process.
The midpoint filter is the average of the maximum and minimum within the window , as follows:
Ordered set  I 1  I 2  I 3  ....  I N 2
Midpoint = ( I 1  I N 2 ) / 2
The midpoint filter is most useful for gaussian and uniform noise
The alpha –trimmed mean filter is the average of the pixel values within the window, but with some of the endpoint –
ranked values excluded.
Ordered set  I 1  I 2  I 3  ....  I N 2
Alpha – trimmed mean =
1
2
N  2
N 2 
I
i T 1
i
Where  is the number of pixel values removed from each end of the list , and can range from 0 to (N2-1)/2 . When =0,
no values are removed from the list and the filter behaves as a mean filter. If =(N2-1)/2 , the equation becomes a median
filter.
4. Adaptive Filters
The spatial filters described in before all perform the same calculation at almost every pixel in an image. However, the
properties of an image can vary spatially. For example in an image corrupted by Gaussian random noise , a mean filter
will be effective in those parts of the image that are supposed to be homogeneous , but will have an blurring effect in the
edges.
This filter compute local grey level statistics within the neighborhood of a pixel and base their behavior on this
information. For example:
g ( x, y )  f ( x, y ) 
 n2



f
(
x
,
y
)

f
(
x
, y )

 ( x, y ) 

2
where 2n is an estimate of noise variance, 2(x,y) is the grey level variance computed for the neighborhood centered on
x,y and f_(x,y0 is the mean grey level in the neighborhood.
In homogeneus regions of an image, noise will be the sole cause of variations in grey level (2n =2(x,y)) and
g(x,y) = f_(x,y)
5. Line Detection
While edges (i.e. boundaries between regions with relatively distinct graylevels) are by far the most common type of
discontinuity in an image, instances of thin lines in an image occur frequently enough that it is useful to have a separate
mechanism for detecting them. Here we present a convolution based technique which produces an image description of
the thin lines in an input image. Note that the Hough transform can be used to detect lines; however, in that case, the
output is a parametric description of the lines in an image.
5. 1. How It Works
The line detection operator consists of a convolution kernel tuned to detect the presence of lines of a particular width n, at
a particular orientation . Figure 1 shows a collection of four such kernels, which each respond to lines of single pixel
width at the particular orientation shown.
Figure 2 Four line detection kernels which respond maximally to horizontal, vertical and oblique (+45
and - 45 degree) single pixel wide lines.
These masks above are tuned for light lines against a dark background, and would give a big negative response to dark
lines against a light background. If you are only interested in detecting dark lines against a light background, then you
should negate the mask values. Alternatively, you might be interested in either kind of line, in which case, you could take
the absolute value of the convolution output. In the discussion and examples below, we will use the kernels above without
an absolute value.
If
denotes the response of kernel i, we can apply each of these kernels across an image, and for any particular point, if
for all
that point is more likely to contain a line whose orientation (and width) corresponds to that of
kernel i. One usually thresholds to eliminate weak lines corresponding to edges and other features with intensity
gradients which have a different scale than the desired line width. In order to find complete lines, one must join together
line fragments, e.g., with an edge tracking operator.
Rank filters – Conclusions
non-linear spatial filters
also called order statistic filters
sort the neighborhood pixels into ascending order
select the one of a given rank to be the ouput value
Median filter
select the median pixel from the sorted list to be the output value
for an n x n neighborhood, this will be the pixel in position floor(n2/2) + 1
removes structure that occupies less than half of the neighborhood
median filter is especially good at removing impulse noise
want the noise to occupy less than half of the neighborhood
can increase the neighborhood size for noisier images
the shape of the neighborhood can affect amount of damage to object edges
Median filter performance
need to sort an array of values at every pixel
choose a sorting algorithm carefully
quicksort
good performance overall
provided in Java 2 (java.util.Arrays)
does not give the best performance on small arrays
insertion sort
may perform better than quicksort on small neighborhoods
histogram approach
compute histogram of neighborhood
search for entry where cumulative histogram is greater than or equal to half of
neighborhood size
can update histogram incrementally when we move to the next pixel
Minimum and maximum filters
take the minimum or maximum pixel in the neighborhood
isn't necessary to sort - faster to just use comparisons
minimum filter - enhances dark areas of image
maximum filter - enhances bright areas of image
Range filter
nonlinear edge detector
output pixel value is the difference between the maximum and minimum pixel values
in a neighborhood
edges are not well localized
Java implementation of rank filters
RankFilterOp.java extends NeighborhoodOp
MedianFilterOp.java extends RankFilterOp
RankFilterTool application
Alpha-trimmed mean filter
a hybrid of linear and nonlinear approaches
sort the neighborhood pixels into ascending order
discard a given number (alpha) from each end of the list
output pixel is the mean of the remaining pixel values
alpha = 0 gives a mean filter
alpha = (n2 - 1)/2 gives a median filter
Minimal mean square error filter
adaptive filter - behavior depends on local image properties
must supply an estimate of noise variance
at each pixel, compute the mean gray-level and gray-level variance of neighborhood
ratio of noise variance estimate to gray-level variance in neighborhood affects
computation of output pixel
where neighborhood variance equals noise variance, output is the mean gray-level
where neighborhood variance is large compared to noise variance (near edges),
output is close to input pixel value
MMSEFilterOp.java
Download