Image Segmentation 229
The trouble is that in general the individual histograms of the objects and background
will overlap, and without prior knowledge of the individual histograms it may be difficult to
find a splitting point. Figure 9.7 illustrates this, assuming in each case that the histograms
for the objects and backgrounds are those of a normal distribution. Then we choose the
Threshold Threshold
FIGURE 9.7: Splitting up a histogram for thresholding
threshold values to be the place where the two histograms cross over.
In practice though, the histograms won’t be as clearly defined as those in Figure 9.7, so
we need some sort of automatic method for choosing a “best” threshold. There are in fact
many different methods; here are two.
Otsu’s Method
This was first described by Nobuyuki Otsu in 1979. It finds the best place to threshold
the image into “foreground” and “background” components so that the inter-class variance—
also known as the between class variance—is maximized. Suppose the image is divided into
foreground and background pixels at a threshold t, and the fractions of each are w
f
and w
b
respectively. Suppose also that the means are µ
f
and µ
b
. Then the inter-class variance is
defined as
w
f
w
b
(µ
f
− µ
b
)
2
.
If an image has n
i
pixels of gray value i, then define p
i
= n
i
/N where N is the total number
of pixels. Thus, p
i
is the probability of a pixel having gray value i. Given a threshold value
t then
w
b
=
t−1
k=0
p
k
,
w
f
=
L−1
k=t
p
k
.
where L is the number of gray values in the image. S ince by definition we must have
L−1
k=0
p
k
= 1
it follows that w
k
+ w
f
= 1. The background weights can be computed by a cumulative
sum of all the p
k
values.