Image thresholding is a technique for segmenting an image into regions based on intensity values. It involves partitioning an image's intensity histogram using one or more threshold values to separate objects from the background. Global thresholding uses a single threshold value while local thresholding uses threshold values that depend on both pixel intensity and local properties around each pixel. Otsu's method selects an optimal threshold by maximizing between-class variance to minimize classification error. Local thresholding using moving averages computes thresholds based on the mean intensity of neighborhoods, which works well for images like text where objects are small relative to the image.
STERILITY TESTING OF PHARMACEUTICALS ppt by DR.C.P.PRINCE
IR.pptx
1. What is Image thresholding ?
• Thresholding is a technique for partitioning
image directly into region based on intensity
value and/or property of these value
– Because of intuitive property ,
– Simplicity of implementation
– Computational speed
• Image thresholding enjoys central place in image
segmentation
1
2. Intensity histogram that can be partitioned
(a) By a single threshold and ( b)by dual threshold
2
3. Thresholding - Foundation
• Suppose that the gray-level histogram
corresponds to an image, f(x,y), composed of
dark objects in a light background, in such a way
that object and background pixels have gray
levels grouped into two dominant modes.
• One obvious way to extract the objects from the
background is to select a threshold ‘T’ that
separates these modes. Then any point (x,y) for
which f(x,y) > T is called an object point,
otherwise, the point is called a background point.
3
4. Foundation (contd.)
• In such a case the histogram has to be partitioned
by multiple thresholds.
• Multilevel thresholding classifies a point (x,y) as
belonging to one object class
if T1 < (x,y) <= T2,
to the other object class
if f(x,y) > T2
and to the background
if f(x,y) <= T1.
4
5. Foundation (contd.)
0 ( , )
( , )
1 ( , )
f x y T
g x y
f x y T
Segmentation is accomplished by scanning the image pixel
by pixel and labeling each pixel as object or background,
depending on whether the grey level is greater or less than
the value of T .
Thresholding works well when a grey level histogram of the
image groups separates the pixels of the object and the
background into two dominant modes. Then a threshold T
can be easily chosen between the modes. 5
6. Basic Global and Local Thresholding
• Thresholding may be viewed as an operation that
involves tests against a function T of the form:
• T = T[x , y , p(x , y) , f(x , y)]
• Where f(x , y) is the gray level , and p(x , y) is some
local property.
• Simple thresholding schemes compare each pixels gray
level with a single global threshold. This is referred to
as Global Thresholding .
• If T depends on both f(x , y) and p(x , y) then this is
referred to a Local Thresholding .
6
7. Basic Global Thresholding
1. Select an initial estimate for T.
2. Segment the image using T. This well produce two groups
of pixels: G1 consisting of all pixels with gray level values>T
and G2 consisting of pixels with values <T.
3. Compute the average gray level values 1 and 2 for the
pixels in regions G1 and G2.
4. Compute a new threshold value: T = ½ [1 + 2 ]
5. Repeat step 2 through 4 until the difference in T in
successive iterations is smaller than a predefined
parameter , To.
7
10. Object Optimal Thresholding (contd.)
• Aim: Select T, that minimizes the average error in
decision.
— PDF of gray level of entire image:
p(z) = P1p1(z) + P2p2(z)
where, P1 & P2 are pixel probabilities of
background & foreground,
respectively.
p1(z) & p2(z) being their PDFs
10
11. Object Optimal Thresholding (contd.)
• Error probability in classifying background as
object :
• Error probability in classifying object as
background :
• Overall probability of error:
11
12. Object Optimal Thresholding (contd.)
• Threshold value for which the error is
minimal:
• Gaussian PDF is:
• Optimal threshold:
12
13. Optimum Thresholding: Otsu’s Method
• Based on a very simple idea: Find the
threshold that minimizes the weighted within-
class variance.
• This turns out to be the same as maximizing
the between-class variance.
• Operates directly on the gray level histogram
[e.g. 256 numbers, P(i)], so it’s fast (once the
histogram is computed).
13
14. Otsu Method: Assumptions
• Histogram (and the image) are bimodal.
• Assumes uniform illumination (implicitly), so
the bimodal brightness behavior arises from
object appearance differences only.
14
15. Otsu Method (contd.)
)
(
)
(
)
(
)
(
)
( 2
2
2
2
1
1
2
t
t
q
t
t
q
t
w
q1(t) P(i)
i 1
t
I
t
i
i
P
t
q
1
2 )
(
)
(
1(t)
iP(i)
q1(t)
i 1
t
2(t)
iP(i)
q2(t )
i t 1
I
The weighted within-class variance is:
Where the class probabilities are estimated as:
And the class means are given by:
15
16. • The individual class variances are:
1
2
(t) [i 1(t)]
2 P(i)
q1(t)
i1
t
2
2
(t) [i 2(t)]
2 P(i)
q2 (t)
it1
I
Otsu Method (contd.)
2
w
2
(t) q1(t)[1 q1 (t)][1(t) 2 (t)]2
Within-class,
from before Between-class
• Total Variance is:
16
17. Otsu Method (contd.)
Example:
6-level Gray scale Image
Result:-
17
Threshold T = 0 T = 1 T = 2 T = 3 T = 4 T = 5
3.1196 1.5268 0.5561 0.4909 0.9779 2.2491
0 1.5928 2.5635 2.6278 2.1417 0.8705
)
(
2
t
w
)
(
2
t
B
18. Variable Thresholding On Local Image Property
• Compute a threshold at every point (x,y) in the image based on specified
local property of neighbourhood of (x,y) .
• The basic approach to local thresholding using standard deviation and
mean of the pixel in a neighbourhood of every point in the image
• Standard deviation = local contrast
• Mean= average intensity.
• Local threshold
Txy = a σxy + b mxy
– The segmented image computed as
1 if f(x,y )>Txy
g(x,y) =
0 if f(x,y )≤Txy
18
19. Local Thresholding using Moving Averages
• Special case of local thresholding method.
• Computing a moving average along scan lines
of an image.
• Scanning carried out line by line in zigzag
pattern to reduce illumination bias.
19
20. Local Thresholding using Moving
Averages (contd.)
• Let Zk+1 intensity of the point at step k+1 in the
scanning sequence.
• The moving average(mean) at this point is given by
=m(k)+1/n(zk+1-zk-n)
– n= number of points used in computing the average
– m(1)=z1/n.
• This algorithm is intialized only once not at every row,
because moving average is computed for every point in
the image.
20
21. Local Thresholding using Moving
Averages (contd.)
• Segmentation is implemented using
1 if f(x,y )>Txy
g(x,y) =
0 if f(x,y )≤Txy
– with Txy=bmxy where b is constant and mxy is
the moving average from eq. at point (x,y )
in the input image
21
22. Let n=5 times the average stroke width .
In this case, average pixel width = 4, hence n=20 and b= 0.5
Local Thresholding using Moving
Averages (contd.)
22
23. Thresholding based on moving averages works well when the objects of
interest are small with respect to the image size.
Example- Images of typed or handwritten text.
Local Thresholding using Moving
Averages (contd.)
23
24. Applications of Thresholding
• Analyze and recognize fingerprints
• During the process of
recovering/analyzing/recognizing photographed
or scanned letters
• Reduce amount of information (e.g. for image
transfer, or content recognition)
• Real-time adaptive thresholding (e.g. face
detection)
• Traffic control and wireless mesh networks
• Motion detection using dynamic thresholding
• Background subtraction (e.g. real-time
subtraction for biometric face detection) 24
25. Conclusion
• Global thresholding: Suitable only when object &
background class are distinctive.
• Optimal Thresholding using Otsu’s method:
Requires maximizing the between class variance
between the object & background class.
• Otsu’s method fails due to improper illumination
on the image.
• Local thresholding using moving average is
suitable for thresholding the hand written text
images
25