You are on page 1of 4

Question 2

THRESHOLD: Threshold is a term which is not only applicable to image processing. In any field threshold
has the same meaning. A threshold is a value which has two regions on its either side i.e. below the
threshold or above the threshold. In general any function can have a threshold. Below the threshold
value the function has an expression while above the value it has another.

e.g. if you want to apply some conversion on each and every pixel in an image then the transformation
function may be a thresholding operation i.e. if the pixel value of the original image is above a particular
value it will follow a particular transformation function, if not, another.

Otsu’s Thresholding Concept

Automatic global thresholding algorithms usually have following steps.

1. Process the input image

2. Obtain image histogram (distribution of pixels)

3. Compute the threshold value 

4. Replace image pixels into white in those regions, where saturation is greater than   and into
the black in the opposite cases.  

Short introduction

Otsu’s method is an adaptive thresholding way for binarization in image processing. By going through all
possible threshold values (from 0 to 255), it can find the optimal threshold value of input image.

1. create histogram for the input image

We assume that the input image is an grayscale image. As for the RGB input image, it should be
converted into grayscale image first.

In Otsu thresholding, statistical data of an image is used. First, we talk about “Histogram”. It is a
representation of the distribution of the data. And…how to create the histogram for an input image?
Very straightforward, take a look to the following example 👇, to calculate the number of every pixel
value in one image and this statistical result is so-called histogram.

Note that the range of the pixel value is from 0 to 255. For convenience, we assume that the pixel value
is not greater than 5 and the pixel value is not related to the color shown in the example.
Histogram for the image

2. Within-class variance

Use the same histogram as an example. If we choose the threshold value T=2, then the image is
separated into two classes, which are Class 1 (pixel value<=2) and Class 2 (pixel value>2). We can say
that these two classes represent background and foreground of the input image respectively. (Class 2
can be the background if foreground is darker than background)

Now, let’s talk about “Variance”. From the following mathematical equation 👇, it can be explained as
the distribution of the data. The higher the value of “Variance”, the more dispersed the data is.

Variance; Xi is the pixel value, μ is the mean, and N is the number of pixels in one image

In terms of the within-class variance (Vw, for short), the lower the value of Vw is, the less dispersed the
data in each class is (background and foreground). As the result, to get the optimal threshold value is to
find the minimal value of Vw.

Here is the example to calculate Vw.


3. Between-class variance

In previous section, we mentioned “within-class variance”. Here, we then talk about “between-class
variance” (Vb, for short). Vb is the variance between two classes. And, to get the suitable threshold
value is to find the maximal value of Vb. I’ll provide two ways to explain.

 Way 1:

There is another technical term “total variance” (Vt, for short), which is the total variance in one image.
Obviously, Vt-Vw=Vb because the variance is either in classes or between classes. In one image, Vt is
held fixed, and Vw is minimal, so that Vb should be maximal.

 Way 2:

We know that there are two classes, which are background and foreground of the image. Consider if Vb
is minimal. It means that the dispersity between two classes is lowest (it is not a good result). As the
result, Vb should be maximal.

Here is the example to calculate Vb.

You might also like