have, and then the shadow will become much fainter. We can also include spatial averaging as
in Section 3.3.2, to reduce further the effect of the walking subject, as shown in Figure 3.22(h).
This gives spatiotemporal averaging. For this, we have not required any more images, but the
penalty paid for the better improvement in the estimate of the background is lack of detail. We
cannot see the numbers in the clock, because of the nature of spatial averaging. However, if we
form the background image by taking the median of the six images, a temporal median,weget
a much better estimate of the background, as shown in Figure 3.22(i). A lot of the image detail
is retained, while the walking subject disappears. In this case, for a sequence of images where
the target walks in front of a static background, the median is the most appropriate operator. If
we did not have a sequence, we could just average the single image with a large operator and
that could provide some estimate of the background.
(a) Image 1 (b) Image 2 (c) Image 3 (d) Image 4 (e) Image 5 (f) Image 6
(g) Temporal averaging (h) Spatiotemporal averaging (i) Temporal median
Figure 3.22 Background estimation by mean and median filtering
3.5.3 Mode filter
The mode is the final statistic of interest, although there are more advanced filtering operators
to come. The mode is very difficult to determine for small populations and theoretically does
not even exist for a continuous distribution. Consider, for example, determining the mode of
the pixels within a square 5×5 template. It is possible for all 25 pixels to be different, so each
could be considered to be the mode. As such, we are forced to estimate the mode: the truncated
median filter, as introduced by Davies (1988), aims to achieve this. The truncated median filter
is based on the premise that for many non-Gaussian distributions, the order of the mean, the
median and the mode is the same for many images, as illustrated in Figure 3.23. Accordingly,
if we truncate the distribution (i.e. remove part of it, where the part selected to be removed in
Figure 3.23 is from the region beyond the mean) then the median of the truncated distribution
will approach the mode of the original distribution.
The implementation of the truncated median, trun_med, operator is given in Code 3.14.
The operator first finds the mean and the median of the current window. The distribution of
intensity of points within the current window is truncated on the side of the mean so that the
median now bisects the distribution of the remaining points (as such, not affecting symmetrical
94 Feature Extraction and Image Processing
No. of points
Mode
Median
Mean
Brightness
Figure 3.23 Arrangement of mode, median and mean
hafloor
wsze
2
winsubmatrix(p,yha,y+ha,xha,x+ha)
medmedian(win)
upper
2
medmin(win)
lower
2
medmax(win)
cc
0
cccc+
1
trun
cc
win
j,i
trun
cc
win
j,i
cccc+
1
if
(
win
j,i
>lower
)
(med>ave)
if
(
win
j,i
<upper
)
(med<ave)
for i
0
..wsze
1
for j
0
..wsze
1
newpic
y,x
median(trun) if cc>
0
newpic
y,x
med otherwise
for yha..rows(p)ha
1
for xha..cols(p)ha
1
newpic
trun_med(p,wsze):= newpiczero(p)
avemean(win)
Code 3.14 The truncated median operator
distributions). So that the median bisects the remaining distribution, if the median is less than
the mean, the point at which the distribution is truncated, upper,is
upper = median +median mindistribution
=2 ·median mindistribution (3.26)
Basic image processing operations 95

Get Feature Extraction & Image Processing, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.