background image

1

 Segmentation – Part 1

 

Thresholding Segmentation Technique

 

Elsayed Hemayed

Fall 2007

This material is a modified version of the slides provided by Milan Sonka, Vaclav Hlavac, and Roger 
Boyle, Image Processing, Analysis, and Machine Vision..

background image

 
Computer Vision

 

Segmentation

2

Outline

What is Segmentation

Segmentation techniques:

1.

Thresholding

2.

Edge-based Segmentation

3.

Region-based Segmentation

4.

Matching

background image

 
Computer Vision

 

Segmentation

3

Segmentation

Goal:

 to divide an image into parts that have a strong 

correlation with objects or areas of the real world, mainly 
objects and background. 

A complete segmentation of an image R is a set of regions 
R1, R2, …, Rs

i

R

S

i

R

1

 

j

i

R

j

background image

 
Computer Vision

 

Segmentation

4

Segmentation

Segmentation may be

Complete segmentation

 - set of disjoint regions 

uniquely corresponding with objects in the input image 

Partial segmentation

 - regions do not correspond 

directly to image objects

background image

5

Thresholding 

Segmentation Technique

Basic, Band, Multi, Semi-Thresholding

Threshold detection methods  

Multi-spectral Thresholding 

Hierarchical Thresholding

Algorithms

Iterative (optimal) Threshold Selection

Recursive multi-spectral thresholding

Re-segmenting boundary pixels

background image

 
Computer Vision

 

Segmentation

6

Advantages

simplest

 segmentation process since Many 

objects or image regions are characterized by 
constant reflectivity or light absorption of their 
surface. 

computationally inexpensive and 

fast

 and can 

easily be done in 

real

 

time

 

background image

 
Computer Vision

 

Segmentation

7

Basic Thresholding

Basic thresholding of an input image f  to an 
output image g is as follows:

g(i,j) = 1   for  f(i,j)  

g(i,j) = 0   for  f(i,j)  

 

T

 

T

Matlab Image Processing Toolbox: im2bw
Convert an image to a binary image, based on 
threshold

Syntax
BW = im2bw(I,threshold/256);

background image

 
Computer Vision

 

Segmentation

8

Band Thresholding

There are several 

modifications

 on basic 

thresholding. They include:
1.

Band

 

thresholding:

g(i,j) = 1   for  f(i,j) 

f(i,j)  

g(i,j) = 0    otherwise

used e.g. in microscopic blood cells

D

Matlab Image Processing Toolbox: roicolor
Select region of interest, based on color

Syntax
BW = roicolor(A,low,high); % 0 <= low, high 
<=256

background image

 
Computer Vision

 

Segmentation

9

Multi-Thresholding

2. Multi-thresholding, using limited set of array levels:

g(i,j) = 1   

for  f(i,j)  

g(i,j) = 2

for  f(i,j)  

g(i,j) = 3

for  f(i,j)  

.
.
.

g(i,j) = n

for  f(i,j)  

g(i,j) = 0

otherwise

1

D

2

D

3

D

n

D

background image

 
Computer Vision

 

Segmentation

10

Semi-Thresholding

3.  Semi-thresholding, masks out background

            g(i,j) =  f(i,j)    for  f(i,j)  

 

     g(i,j) = 0   for  f(i,j)   

T

T

background image

 
Computer Vision

 

Segmentation

11

Threshold Detection techniques 

If some property of an image after segmentation 
is known a priori, the task of threshold selection 
is simplified, since the threshold is chosen to 
ensure this property is satisfied. 

A main detection technique is based on 

Histogram shape analysis:

 

The chosen threshold is chosen to meet minimum 
segmentation error, by selecting it as the gray level 
that has 

minimum histogram value between the two 

maxima

, that represent objects and background in the 

image.

background image

 
Computer Vision

 

Segmentation

12

Histogram shape analysis

Distribution of 
Background

Distribution of 
Objects

Threshold 
Value

Matlab Image Processing Toolbox: imhist
Display a histogram of image data

Syntax
imhist(I);

background image

 
Computer Vision

 

Segmentation

13

Thresholding Examples

background image

 
Computer Vision

 

Segmentation

14

Segmentation Example 1

background image

 
Computer Vision

 

Segmentation

15

Segmentation Example 2

background image

 
Computer Vision

 

Segmentation

16

Histogram shape analysis 

(cont.)

Distribution of 
Background

Distribution of 
Objects

Threshold 
Value 

?

background image

 
Computer Vision

 

Segmentation

17

Histogram shape analysis

P-tile thresholding

Weighted histograms 

Optimal thresholding

background image

 
Computer Vision

 

Segmentation

18

P-tile thresholding

Threshold is selected such that 

1/p 

of image pixels 

has gray values less than T.

A good example is processing text pages.

1/p

background image

 
Computer Vision

 

Segmentation

19

One option is to 

weight histogram

 contribution:

Excluding

 pixels with 

high gradient values

 that 

represent edges will result in histogram with deeper 
valley and threshold will be easier to detect.

Building histogram for 

pixels with high gradient value 

only

, the threshold value would be the peak of this 

histogram.

Weighted histograms 

background image

 
Computer Vision

 

Segmentation

20

Optimal thresholding

It approximates histogram using two or more 
probabilities with 

normal distribution

. The 

threshold is then the min probability between 
the maxima of the these normal distributions. 

It results in 

minimum error segmentation. 

background image

 
Computer Vision

 

Segmentation

21

Optimal thresholding

background image

 
Computer Vision

 

Segmentation

22

Threshold Detection techniques

Actual Example 

background image

 
Computer Vision

 

Segmentation

23

Brain MR Image Segmentation

background image

 
Computer Vision

 

Segmentation

24

Apple Grading

Results of segmentation by isodata thresholding. Fruits displayed are 
defected by scald (top-left), rot (top-right), frost damage (mid-left), 
bruise (mid-right), hail damage perfusion (bottom-left) and flesh 
damage (bottom-right). For each fruit its original RGB image, its 
manual segmentation (ground truth) and its segmentation results are 
displayed in a row. Defected areas are displayed in white in ground 
truth images, whereas segmentations show defected regions in gray 
color and healthy ones in white.

Courtesy of D. UNAY, B. GOSSELIN, 2005, 

"Thresholding

-based Segmentation and Apple Grading by Machine Vision"

, Proc. of EUSIPCO 2005, Antalya, Turkey.

background image

 
Computer Vision

 

Segmentation

25

Algorithm:

 Iterative (optimal) 

Threshold Selection

1. As first iteration consider that the 4 corners contain 

background pixels only and the remainder contains 

object pixels.

2. Calculate       and        as the average     
   intensity of background and object pixels. 
3. At step t+1 segmentation is performed using the 

threshold

      

t

B

t

O

background image

 
Computer Vision

 

Segmentation

26

Iterative (optimal) Threshold 

Selection (cont.)

4. Re-calculate      and     according to new 

segmentation using:

5. Re-calculate 
6. Stop if  

t

B

t

O

)

(

)

1

(

t

t

T

T

An implementation of the Iterative Threshold Selection by 
Dhanesh Ramachandram is available online at:

http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=
3195&objectType=file

func_threshold 

Matlab File

background image

 
Computer Vision

 

Segmentation

27

1.

Initiallize

 the whole image as a single region.

2.

Compute a smoothed 

histogram for each spectral band

.

3.

Find the 

most significant peak in each

 histogram and 

determine 

two thresholds

 on either sides of the peak.

4.

Segment each region

 in each spectral band into sub-

regions according to these thresholds.

Algorithm:

 

Recursive multi-

spectral thresholding

background image

 
Computer Vision

 

Segmentation

28

Recursive multi-spectral 

thresholding (cont.):

background image

 
Computer Vision

 

Segmentation

29

5.

Project

 

each segmentation into a multi-spectral 

segmentation.

6.

Regions for the next processing

 steps are those in the 

multi-spectral image. 

7.

Repeat

 2-6 

until

 each histogram contains 

only one 

significat peak.

Recursive multi-spectral 

thresholding (cont.):

background image

 
Computer Vision

 

Segmentation

30

Demo:

 Multi-spectral thresholding

background image

 
Computer Vision

 

Segmentation

31

1.

The presence of a region is detected in a low 
resolution image

2.

Then more precision is given moving to higher 
resolution by re-segmenting pixels close to 
boundaries. 

Advantage:

 lower influence of noise!

Algorithm:

 Re-segmenting boundary pixels

(

Thresholding in hierarchical data structures)

background image

 
Computer Vision

 

Segmentation

32

Demo:

 Re-segmenting boundary pixels

background image

 
Computer Vision

 

Segmentation

33

Summary

Basic, Band, Multi, Semi-Thresholding

Threshold detection methods  

Multi-spectral thresholding 

Hierarchical Thresholding

Algorithms

Iterative (optimal) Threshold Selection

Recursive multi-spectral thresholding

Re-segmenting boundary pixels


Document Outline