binary image analysis selim aksoy department of computer engineering bilkent university...

76
Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University [email protected]

Upload: kayla-muscat

Post on 31-Mar-2015

217 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

Binary Image Analysis

Selim AksoyDepartment of Computer Engineering

Bilkent [email protected]

Page 2: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 2

Outline

Introduction to binary image analysis Mathematical morphology Pixels and neighborhoods Connected components analysis Automatic thresholding

Page 3: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 3

Binary image analysis

Binary image analysis consists of a set of operations that are used to produce or process binary images, usually images of 0’s and 1’s where 0 represents the background, 1 represents the foreground.

000100100010000001111000100000010010001000

Page 4: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 4

Application areas

Document analysis

Industrial inspection

Medical imagingAdapted from Shapiro and Stockman

Page 5: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 5

Operations

Separate objects from background and from one another.

Aggregate pixels for each object.

Compute features for each object.

Page 6: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 6

Example: red blood cell image Many blood cells are

separate objects. Many touch each other

bad! Salt and pepper noise

is present. How useful is this data?

63 separate objects are detected.

Single cells have area of about 50 pixels.

Adapted from Linda Shapiro, U of Washington

Page 7: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 7

Thresholding Binary images can be obtained from gray

level images by thresholding. Assumptions for thresholding:

Object region of interest has intensity distribution different from background.

Object pixels likely to be identified by intensity alone:

intensity > a intensity < b a < intensity < b

Works OK with flat-shaded scenes or engineered scenes.

Does not work well with natural scenes.

Page 8: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 8

Use of histograms for thresholding

Background is black.

Healthy cherry is bright.

Bruise is medium dark.

Histogram shows two cherry regions (black background has been removed).

Adapted from Shapiro and Stockman

Page 9: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 9

Mathematical morphology

The word morphology refers to form and structure.

In computer vision, it is used to refer to the shape of a region.

The language of mathematical morphology is set theory where sets represent objects in an image.

We will discuss morphological operations on binary images whose components are sets in the 2D integer space Z2.

Page 10: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 10

Mathematical morphology

Mathematical morphology consists of two basic operations dilation erosion

and several composite relations opening closing conditional dilation …

Page 11: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 11

Dilation

Dilation expands the connected sets of 1s of a binary image.

It can be used for

growing features

filling holes and gaps

Adapted from Linda Shapiro, U of Washington

Page 12: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 12

Erosion

Erosion shrinks the connected sets of 1s of a binary image.

It can be used for

shrinking features

removing bridges, branches and small protrusions

Adapted from Linda Shapiro, U of Washington

Page 13: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 13

Basic concepts from set theory

Page 14: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 14

Basic concepts from set theory

Adapted from Gonzales and Woods

Page 15: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 15

Basic concepts from set theory

Page 16: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 16

Logic operations

Adapted from Gonzales and Woods

Page 17: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 17

Structuring elements

Structuring elements are small binary images used as shape masks in basic morphological operations.

They can be any shape and size that is digitally representable.

One pixel of the structuring element is denoted as its origin.

Origin is often the central pixel of a symmetric structuring element but may in principle be any chosen pixel.

Page 18: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 18

Structuring elements

Adapted from Gonzales and Woods,and Shapiro and Stockman

Page 19: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 19

Dilation

Page 20: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 20

Dilation

Binary image A

Structuring element B

Dilation result

1 1 1 1 1 1 1

1 1 1 1

1 1 1 1

1 1 1 1 1

1 1 1 1

1 11 1 1

1 1 1

1 1 1

1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1

0 1 1 1 1 1 1 1

0 1 1 1 1 1 1 1

0 1 1 1 1 1 1 1

0 1 1 1 1 1 1 1

0 1 1 1 1 0 0 0

(1st definition)

Page 21: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 21

Dilation

Structuring element B

Dilation result

1 1 1 1 1 1 1

1 1 1 1

1 1 1 1

1 1 1 1 1

1 1 1 1

1 11 1 1

1 1 1

1 1 1

1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1

1 1 1 1 1 1 1 1

1 1 1 1 1 1 1

1 1 1 1 1 1 1

1 1 1 1 1 1 1

1 1 1 1 1 1 1

1 1 1 1

(2nd definition)

Binary image A

Page 22: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 22

Dilation

Pablo Picasso, Pass with the Cape, 1960

StructuringElement

Adapted from John Goutsias, Johns Hopkins Univ.

Page 23: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 23

Dilation

Adapted from Gonzales and Woods

Page 24: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 24

Erosion

Page 25: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 25

Erosion

Binary image A

Structuring element B

Erosion result

1 1 1 1 1 1 1

1 1 1 1

1 1 1 1

1 1 1 1 1

1 1 1 1

1 11 1 1

1 1 1

1 1 1

0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0

0 0 0 0 1 1 0 0

0 0 0 0 1 1 0 0

0 0 0 0 1 1 0 0

0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0

0 0 0 0 0 0 0 0

(1st definition)

Page 26: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 26

Erosion

Structuring element B

Erosion result

1 1 1 1 1 1 1

1 1 1 1

1 1 1 1

1 1 1 1 1

1 1 1 1

1 11 1 1

1 1 1

1 1 1

1 1

1 1

1 1

(2nd definition)

Binary image A

Page 27: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 27

Erosion

Pablo Picasso, Pass with the Cape, 1960

StructuringElement

Adapted from John Goutsias, Johns Hopkins Univ.

Page 28: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 28

Erosion

Adapted from Gonzales and Woods

Page 29: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 29

Opening

Page 30: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 30

Opening

Structuring element B

Opening result

1 1 1 1 1 1 1

1 1 1 1

1 1 1 1

1 1 1 1 1

1 1 1 1

1 11 1 1

1 1 1

1 1 1

1 1

1 1

1 1

1 1 1 1

1 1

1 1

1 1

1 1 1 1

Binary image A

Page 31: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 31

Opening

Pablo Picasso, Pass with the Cape, 1960

StructuringElement

Adapted from John Goutsias, Johns Hopkins Univ.

Page 32: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 32

Closing

Page 33: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 33

Closing

Binary image A

Structuring element B

Closing result

1 1 1 1 1 1 1

1 1 1 1

1 1 1 1

1 1 1 1 1

1 1 1 1

1 11 1 1

1 1 1

1 1 1

1 1 1 1 1 1

1 1 1 1 1

1 1 1 1 1

1 1 1 1 1

1 1 1 1 1

1 1

Page 34: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 34

Examples

Adapted from Gonzales and Woods

Page 35: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 35

Examples

Original image Eroded once Eroded twice

Page 36: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 36

Examples

Original image

Original image

Opened twice

Closed once

Page 37: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 37

Examples

Adapted from Gonzales and Woods

Page 38: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 38

Examples Gear tooth inspection

<- original binary image

<- detected defects

How did they do it?

Adapted from Shapiro and Stockman

Page 39: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 39

Examples

Adapted from Shapiro and Stockman

Page 40: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 40

Properties

Page 41: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 41

Properties

Page 42: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 42

Boundary extraction

Page 43: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 43

Boundary extraction

Adapted from Gonzales and Woods

Page 44: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 44

Conditional dilation

Page 45: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 45

Region filling

Page 46: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 46

Region filling

Adapted from Gonzales and Woods

Page 47: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 47

Region filling

Adapted from Gonzales and Woods

Page 48: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 48

Hit-or-miss transform

Page 49: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 49

Hit-or-miss transform

Adapted from Gonzales and Woods

Page 50: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 50

Thinning

Page 51: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 51

Thinning

Page 52: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 52

Thickening

Page 53: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 53

Thickening

Adapted from Gonzales and Woods

Page 54: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 54

Examples

Detecting runways in satellite airport imagery

http://www.mmorph.com/mxmorph/html/mmdemos/mmdairport.html

Page 55: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 55

Examples

Segmenting letters, words and paragraphs

http://www.mmorph.com/mxmorph/html/mmdemos/mmdlabeltext.html

Page 56: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 56

Examples

Extracting the lateral ventricle from an MRI image of the brain

http://www.mmorph.com/mxmorph/html/mmdemos/mmdbrain.html

Page 57: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 57

Examples

Detecting defects in a microelectronic circuit

http://www.mmorph.com/mxmorph/html/mmdemos/mmdlith.html

Page 58: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 58

Examples

Decomposing a printed circuit board in its main parts

http://www.mmorph.com/mxmorph/html/mmdemos/mmdpcb.html

Page 59: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 59

Examples

Grading potato quality by shape and skin spots

http://www.mmorph.com/mxmorph/html/mmdemos/mmdpotatoes.html

Page 60: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 60

Examples

Classifying two dimensional pieces

http://www.mmorph.com/mxmorph/html/mmdemos/mmdpieces.html

Page 61: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 61

Pixels and neighborhoods In many algorithms, not only the value of a

particular pixel, but also the values of its neighbors are used when processing that pixel.

The two most common definitions for neighbors are the 4-neighbors and the 8-neighbors of a pixel.

Page 62: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 62

Pixels and neighborhoods

Page 63: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 63

Pixels and neighborhoods

Page 64: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 64

Connected components analysis Suppose that B is a binary image and that

B[r,c] = B[r’,c’] = v where either v = 0 or v = 1. The pixel [r,c] is connected to the pixel [r’,c’]

with respect to value v if a sequence of pixels forms a connected path from [r,c] to [r’,c’] in which all pixels have the same value v, and each pixel in the sequence is a neighbor of the

previous pixel in the sequence. A connected component of value v is a set of

pixels, each having value v, and such that every pair of pixels in the set are connected with respect to v.

Page 65: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 65

Connected components analysis Once you have a binary image, you can identify

and then analyze each connected set of pixels. The connected components operation takes in a

binary image and produces a labeled image in which each pixel has the integer label of either the background (0) or a component.

Binary image after morphology

Connected components

Page 66: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 66

Connected components analysis

Methods for connected components analysis: Recursive tracking (almost never used) Parallel growing (needs parallel hardware) Row-by-row (most common)

Classical algorithm Run-length algorithm

(see Shapiro-Stockman)

Adapted from Shapiro and Stockman

Page 67: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 67

Connected components analysis Recursive labeling algorithm:

1. Negate the binary image so that all 1s become -1s.2. Find a pixel whose value is -1, assign it a new

label, call procedure search to find its neighbors that have values -1, and recursively repeat the process for these neighbors.

Page 68: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 68

Adapted from Shapiro and Stockman

Page 69: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 69

Connected components analysis

Row-by-row labeling algorithm:1. The first pass propagates a pixel’s label to its

neighbors to the right and below it.(Whenever two different labels can propagate to the same pixel, these labels are recorded as an equivalence class.)

2. The second pass performs a translation, assigning to each pixel the label of its equivalence class.

A union-find data structure is used for efficient construction and manipulation of equivalence classes represented by tree structures.

Page 70: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 70

Connected components analysis

Adapted from Shapiro and Stockman

Page 71: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 71

Connected components analysis

Adapted from Shapiro and Stockman

Page 72: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 72

Connected components analysis

Adapted from Shapiro and Stockman

Page 73: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 73

Page 74: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 74

Automatic thresholding

How can we use a histogram to separate an image into 2 (or several) different regions?

Is there a single clear threshold? 2? 3?

Adapted from Shapiro and Stockman

Page 75: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 75

Automatic thresholding: Otsu’s method

Assumption: the histogram is bimodal. Method: find the threshold t that minimizes

the weighted sum of within-group variances for the two groups that result from separating the gray levels at value t.

The best threshold t can bedetermined by a simplesequential search throughall possible values of t.

If the gray levels are strongly dependent on the location within the image, local or dynamic thresholds can also be used.

t

Group 1 Group 2

Page 76: Binary Image Analysis Selim Aksoy Department of Computer Engineering Bilkent University saksoy@cs.bilkent.edu.tr

CS 484, Spring 2007 ©2007, Selim Aksoy 76

Automatic thresholding: Otsu’s method

Adapted from Shapiro and Stockman