This action might not be possible to undo. Are you sure you want to continue?

# Auto_thresholding_clustering: 1 Copyright © 2011: Paul F. Whelan.

**Automated Thresholds – Clustering
**

Thresholding Revisited!

- View as a clustering problem – problem is that the range of values may overlap

- Want to minimise the error in classification (e.g. misclassifying a foreground pixel

as a background one)

Auto_thresholding_clustering: 2 Copyright © 2011: Paul F. Whelan.

Automated Thresholds – Otsu Method

N. Otsu (1979). "A threshold selection method from gray-level histograms". IEEE Trans. Sys., Man., Cyber. 9: 62–66

Otsu method: Simple idea, find the threshold that minimizes the weighted intra (within) class

variance.

This is the same as the same as maximizing the inter (between) class variance

Set the threshold so each cluster is as tight as possible with a view to minimizing any overlap (!)

- Cannot change the distributions so we adjust where we separate them (threshold)

- As we adjust the threshold one way we increase the spread of one and decrease the spread

of the other

Goal: to select threshold that minimizes the combined spread

Auto_thresholding_clustering: 3 Copyright © 2011: Paul F. Whelan.

- Assumes the image to be threshold contains two classes of pixels (bimodal -

foreground and background)

- Calculates the OPTIMAL threshold to separate these two classes so that their

combined intra (within) class variance is minimal

- Operates directly on a pre computed grey level histogram – fast!

- Based solely on intensity information – no spatial context.

- Assumes uniform illumination (implicitly), so the bimodal brightness behavior

arises only from differences in the objects appearance.

Auto_thresholding_clustering: 4 Copyright © 2011: Paul F. Whelan.

Weighted within class variance between object (O) and the background (B) is:

) ( ) ( ) ( ) ( ) (

2 2 2

t t t t t

O O B B within

o e o e o + =

Where the class probabilities are estimated as:

¿

÷

=

=

1

0

) ( ) (

t

i

B

i p t e

¿

÷

=

=

1

) ( ) (

N

t i

O

i p t e

) (

2

t

B

o

= the variance of the pixels in the background (below threshold)

) (

2

t

O

o

= the variance of the pixels in the foreground (above threshold)

[0, N-1] is the range of intensity values.

Auto_thresholding_clustering: 5 Copyright © 2011: Paul F. Whelan.

Mean (Expected Value)

| |

¿

=

= =

N

i

i i

p x x E

1

µ

Variance

| |

2

1

2 2

) ( ) ( µ µ o ÷ = ÷ =

¿

=

i p x E

N

i

i

Class means are given by:

¿

÷

=

=

1

0

) (

) (

) (

t

i

B

B

t

i ip

t

e

µ

¿

÷

=

=

1

) (

) (

) (

N

t i

O

O

t

i ip

t

e

µ

Individual class variances are:

¿

÷

=

÷ =

1

0

2 2

) (

) (

)] ( [ ) (

t

i

B

B B

t

i p

t i t

e

µ o

¿

÷

=

÷ =

1

2 2

) (

) (

)] ( [ ) (

N

t i

O

O O

t

i p

t i t

e

µ o

Auto_thresholding_clustering: 6 Copyright © 2011: Paul F. Whelan.

- Computing the within class variance for each of our two classes for each possible

threshold (ie run through the full range of t values [0,N-1] and pick the value that

minimizes

) (

2

t

within

o

) is computational expensive so we reformulate the problem

- The relationship between the within-class and between-class variances can be

exploited to generate a recursion relation that permits a much faster calculation.

- Between class variance = total variance – within class variance

) ( ) (

2 2 2

t t

within between

o o o ÷ =

2 2

] ) ( )[ ( ] ) ( )[ ( µ µ e µ µ e ÷ + ÷ = t t t t

O O B B

Where

2

o

is the combined variance, and

µ

is the combined mean

- The between class variance is simply the weighted variance of the cluster means

themselves around the overall mean.

Auto_thresholding_clustering: 7 Copyright © 2011: Paul F. Whelan.

Substituting

) ( ) ( ) ( ) ( t t t t

O O B B

µ e µ e µ + =

and simplifying we get

2 2

)] ( ) ( )[ ( ) ( ) ( t t t t t

O B O B between

µ µ e e o ÷ =

Algorithm

- Compute histogram and probabilities of each intensity level

- Set up initial e

i

(0) and μ

i

(0)

- For each potential threshold

1. Separate the pixels into two clusters according to the threshold

2. Find the mean of each cluster

3. Square the difference between the means

4. Multiply by the number of pixels in each cluster

- Desired threshold corresponds to the maximum

) (

2

t

between

o

Still computationally expensive!

Auto_thresholding_clustering: 8 Copyright © 2011: Paul F. Whelan.

Otsu Method – Iterative approach

- The nice thing about this is that we can compute the quantities in

) (

2

t

between

o

recursively as we

run through the range of t values.

- Computations are not independent as we change from one threshold to another

- We can update ω

B

(T) and ω

O

(T) and the respective cluster means μ

B

(T) and μ

O

(T) as pixels

move from one cluster to the other as t increases.

- Using recurrence relations we can update the between-class variance as we successively

test each threshold:

Initialization:

) 1 ( ) 1 ( p

B

= e

0 ) 0 ( =

b

µ

Recursion:

) ( ) ( ) 1 ( t p t t

B B

+ = + e e

) ( ) ( ) 1 ( t p t t

O O

÷ = + e e

) 1 (

) ( ) ( ) (

) 1 (

+

+

= +

t

t t p t t

t

B

B B

B

e

µ e

µ

) 1 (

) ( ) ( ) (

) 1 (

+

÷

= +

t

t t p t t

t

O

O O

O

e

µ e

µ

Auto_thresholding_clustering: 9 Copyright © 2011: Paul F. Whelan.

May fail when object and background pixels are extremely unbalanced!

Otsu threshold

131

Auto_thresholding_clustering: 10 Copyright © 2011: Paul F. Whelan.

Dr. Andrew Greensted - labbookspages - worked example (threshold = 3)

Auto_thresholding_clustering: 11 Copyright © 2011: Paul F. Whelan.

Auto_thresholding_clustering: 12 Copyright © 2011: Paul F. Whelan.

Works well for images with a bimodal histogram

Auto_thresholding_clustering: 13 Copyright © 2011: Paul F. Whelan.

9: 62–66 Otsu method: Simple idea. Sys. Whelan. .. "A threshold selection method from gray-level histograms". This is the same as the same as maximizing the inter (between) class variance Set the threshold so each cluster is as tight as possible with a view to minimizing any overlap (!) Cannot change the distributions so we adjust where we separate them (threshold) As we adjust the threshold one way we increase the spread of one and decrease the spread of the other Goal: to select threshold that minimizes the combined spread Auto_thresholding_clustering: 2 Copyright 2011: Paul F. Cyber. IEEE Trans.. find the threshold that minimizes the weighted intra (within) class variance.Automated Thresholds – Otsu Method N. Otsu (1979). Man.

Assumes the image to be threshold contains two classes of pixels (bimodal foreground and background) Calculates the OPTIMAL threshold to separate these two classes so that their combined intra (within) class variance is minimal Operates directly on a pre computed grey level histogram – fast! Based solely on intensity information – no spatial context. . Assumes uniform illumination (implicitly). Auto_thresholding_clustering: 3 Copyright 2011: Paul F. Whelan. so the bimodal brightness behavior arises only from differences in the objects appearance.

. Auto_thresholding_clustering: 4 Copyright 2011: Paul F. N-1] is the range of intensity values. Whelan.Weighted within class variance between object (O) and the background (B) is: 2 2 2 within (t ) B (t ) B (t ) O (t ) O (t ) Where the class probabilities are estimated as: B (t ) p(i) i 0 t 1 O (t ) p(i) i t N 1 2 B (t ) = the variance of the pixels in the background (below threshold) 2 O (t ) = the variance of the pixels in the foreground (above threshold) [0.

Whelan.Mean (Expected Value) Ex xi pi i 1 N Variance 2 E ( x ) pi (i ) 2 2 i 1 N Class means are given by: ip (i) B (t ) i 0 B (t ) t 1 O (t ) i t N 1 ip (i) O (t ) Individual class variances are: p(i) (t ) [i B (t )] B (t ) i 0 2 B 2 t 1 (t ) [i O (t )]2 2 O i t N 1 p(i) O (t ) Auto_thresholding_clustering: 5 Copyright 2011: Paul F. .

Whelan.N-1] and pick the value that 2 minimizes within (t ) ) is computational expensive so we reformulate the problem The relationship between the within-class and between-class variances can be exploited to generate a recursion relation that permits a much faster calculation. and Where is the combined mean The between class variance is simply the weighted variance of the cluster means themselves around the overall mean. Between class variance = total variance – within class variance 2 2 between (t ) 2 within(t ) B (t )[B (t ) ]2 O (t )[O (t ) ]2 2 is the combined variance. Computing the within class variance for each of our two classes for each possible threshold (ie run through the full range of t values [0. Auto_thresholding_clustering: 6 Copyright 2011: Paul F. .

Square the difference between the means 4. Find the mean of each cluster 3. Multiply by the number of pixels in each cluster Desired threshold corresponds to the maximum 2 between (t ) Still computationally expensive! Auto_thresholding_clustering: 7 Copyright 2011: Paul F. Whelan. Separate the pixels into two clusters according to the threshold 2. .Substituting B (t )B (t ) O (t )O (t ) and simplifying we get Algorithm 2 between (t ) B (t )O (t )[B (t ) O (t )] 2 Compute histogram and probabilities of each intensity level Set up initial i(0) and μi(0) For each potential threshold 1.

Computations are not independent as we change from one threshold to another We can update ωB(T) and ωO(T) and the respective cluster means μB(T) and μO(T) as pixels move from one cluster to the other as t increases. .Otsu Method – Iterative approach 2 The nice thing about this is that we can compute the quantities in between (t ) recursively as we run through the range of t values. Using recurrence relations we can update the between-class variance as we successively test each threshold: Initialization: Recursion: B (1) p(1) b (0) 0 B (t 1) B (t ) p(t ) B (t 1) B (t ) B (t ) p(t )t B (t 1) O (t 1) O (t ) p(t ) O (t 1) O (t ) O (t ) p(t )t O (t 1) Auto_thresholding_clustering: 8 Copyright 2011: Paul F. Whelan.

Whelan.Otsu threshold 131 May fail when object and background pixels are extremely unbalanced! Auto_thresholding_clustering: 9 Copyright 2011: Paul F. .

.labbookspages . Whelan.Dr.worked example (threshold = 3) Auto_thresholding_clustering: 10 Copyright 2011: Paul F. Andrew Greensted .

Whelan.Auto_thresholding_clustering: 11 Copyright 2011: Paul F. .

Whelan.Works well for images with a bimodal histogram Auto_thresholding_clustering: 12 Copyright 2011: Paul F. .

Auto_thresholding_clustering: 13 Copyright 2011: Paul F. . Whelan.