You are on page 1of 165

PDF processed with CutePDF evaluation edition www.CutePDF.

com

Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

The whole is equal to the sum of its parts.


-Euclid

The whole is greater than the sum of its parts.


-Max Wertheimer

The Whole is Not Equal to the Sum of Its Parts:


An Approach to Teaching the Research Paper.
-by Mangum, Bryant

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

10.1 Detection of Discontinuities


10.2 Edge Linking and Boundary Detection
10.3 Thresholding
10.4 Region-Based Segmentation
10.5 Segmentation by Morphological Watersheds (x)
10.6 The Use of Motion in Segmentation

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

10.1 Detection of Discontinuities 568


10.1.1 Point Detection 569
10.1.2 Line Detection 570
10.1.3 Edge Detection 572

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

Point Detection

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

Line Detection

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

Edge Detection

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

10.2 Edge Linking and Boundary Detection 585


10.2.1 Local Processing 585
10.2.2 Global Processing via the Hough Transform 587
10.2.3 Global Processing via Graph-Theoretic Techniques 591

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

Local Processing

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

Global Processing via the Hough Transform

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

Global Processing via Graph-Theoretic Techniques

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

10.3 Thresholding 595


10.3.1 Foundation 595
10.3.2 The Role of Illumination 596
10.3.3 Basic Global Thresholding 598
10.3.4 Basic Adaptive Thresholding 600
10.3.5 Optimal Global and Adaptive Thresholding 602
10.3.6 Use of Boundary Characteristics for Histogram Improvement
and Local Thresholding 608
10.3.7 Thresholds Based on Several Variables 611

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

Foundation

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

The Role of Illumination

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

Basic Global Thresholding

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

Basic Adaptive Thresholding


© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

Optimal Global and Adaptive Thresholding

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

Use of Boundary Characteristics for Histogram Improvement


and Local Thresholding

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

10.4 Region-Based Segmentation 612


10.4.1 Basic Formulation 612
10.4.2 Region Growing 613
10.4.3 Region Splitting and Merging 615

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

Region
Growing

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

Region Splitting and Merging

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

10.5 Segmentation by Morphological Watersheds 617


10.5.1 Basic Concepts 617
10.5.2 Dam Construction 620
10.5.3 Watershed Segmentation Algorithm 622
10.5.4 The Use of Markers 624

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

10.6 The Use of Motion in Segmentation


Stationary camera
Background modeling
Human tracking & extraction
Moving camera
3D Reconstruction
Moving target detecting

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

© 2002 R. C. Gonzalez & R. E. Woods


Digital Image Processing, 2nd ed. www.imageprocessingbook.com

Chapter 10
Image Segmentation

b c

Plane parameters in blue and motion in red


compression ratio is 10,000:1
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing
(UST 2007 Fall)

Sang Chul Ahn


asc@imrc.kist.re.kr

Image Segmentation
Image Segmentation
Æ Goal: Segmentation subdivides an image into its
constituent regions or objects that have similar
features according to a set of predefined criteria
Æ features?
Æ intensity
Æ histogram
Æ mean, variance
Æ energy
Æ texture
Æ ….
Æ It depends on applications or the problems to
solve

Image Processing Steps

segmentation
enhancement Image
Preprocessing Analysis feature extraction,
restoration, etc
etc

Image Knowledge Recognition


Acquisition Base & Interpretation
Detection of Discontinuities
Æ3 basic types of gray-level discontinuities: points, lines,
edges
Æ We segment the image along the discontinuities
Æ The most common way to look for discontinuities is to run
a mask through the image
Æ Spatial filter(mask)
ex) R = w1 z1+ w2 z2+…+ w9 z9

w1 w2 w3

w4 w5 w6

w7 w8 w9

mask

Point Detection
Æ We say that a (isolated) point has been detected at the location on
which the mask is centered if
|R| > T, R: spatial filtering result, T: nonnegative threshold

-1 -1 -1

-1 8 -1

-1 -1 -1

Æ The formulation measures the weighted differences between the


center point and its neighbors
Æ This filter is a highpass spatial filter(Laplacian)
Æ The filter detects a point whose gray level is significantly different
from its background
Æ The result depends on the threshold T
Point Detection

(a) original image (b) highpass filtered image

Thresholding of (b), T=100 Thresholding of (b), T=200

Point Detection
Æ X-ray image of a jet-engine turbine blade with a porosity
in the upper, right quadrant of the image
Æ The threshold T is set to 90% of the highest absolute
pixel value of the image in Fig. 10.2(c)
Line Detection

Æ These filter masks would respond more strongly to lines


Æ Note that the coefficients in each mask sum to zero,
indicating a zero response from the masks in areas of
constant gray level
Æ If we are interested in detecting lines in a specified
direction, we could use the mask associated with that
direction and threshold its output
Æ Note: these filters respond strongly to lines of one pixel
thick

Line Detection
Æ A binary image of a wire-bond
mask for an electronic circuit
Æ We are interested in finding all
the lines that are one pixel thick
and are oriented at -45°
Æ The line in the top, left quadrant
is not detected because it is not
one pixel thick
Edge Detection
Æ Edge detection is the most common approach for
detecting meaningful discontinuities
Æ Edge
Æ An edge is a set of connected pixels that lie on the boundary
between two regions
Æ An edge is a “local” concept whereas a region boundary is a
more global idea
Æ A reasonable definition of “edge” requires the ability to measure
gray level(intensity) transitions in a meaningful way
Æ An ideal edge has the properties of the model shown in
Fig. 10.5(a)
Æ An ideal edge according to this model is a set of
connected pixels, each of which is located at an
orthogonal step transition in gray level

Edge Detection
Æ In practice, optics, sampling, and other image acquisition
imperfections yeild edges that are blurred
Æ As a result, edges are more closely modeled as a “ramp”-like profile
Æ The degree of blurring is determined by factors such as the quality of
the image acquisition system, the sampling rate, and illumination
conditions
Æ An edge point is any point contained in the ramp, and an edge would
be a set of such points that are connected
Æ The “thickness” of the edge is determined by the length of the ramp
Æ Blurred edges tend to be thick and sharp edges tend to be thin
Edge Detection
Æ The magnitude of the first derivative can be used to detect the
presence of an edge
Æ The sign of the second derivative can be used to determine whether
an edge pixel lies on the dark or light side of an edge
Æ An imaginary straight line joining the extreme positive and negative
values of the second derivative would cross zero near the midpoint of
the edge (zero-crossing property)

Edge Detection

Æ Derivative is very
sensitive to noise
Æ Image smoothing is
needed
Edge Detection
Æ We define a point in an image as being an edge point if
its two-dimensional first-order derivative is greater than a
specified threshold
Æ A set of such points that are connected according to a
predefined criterion of connectedness is defined as an
edge
Æ The term edge segment generally is used if the edge is
short in relation to the dimensions of the image
Æ A key problem in segmentation is to assemble edge
segments into longer edges

Gradient Operators
Æ First-order derivatives of a digital image are based on various
approximations of the 2-D gradient
Æ The gradient is defined as the two-dimensional column vector
Æ The magnitude of the gradient vector often is referred to as the
gradient, too
⎡ ∂f ⎤ ∇f = mag(∇f ) = [G x2 + GY2 ]1 / 2
⎡G x ⎤ ⎢ ∂x ⎥
∇f = ⎢ ⎥ = ⎢ ∂f ⎥
1/ 2
G ⎡⎛ ∂f ⎞ 2 ⎛ ∂f ⎞ 2 ⎤
⎣ y ⎦ ⎢ ⎥
= ⎢⎜ ⎟ + ⎜⎜ ⎟⎟ ⎥
⎢⎣ ∂ y ⎥⎦
⎢⎣⎝ ∂x ⎠ ⎝ ∂y ⎠ ⎥⎦

Æ We usually approximate the magnitude by absolute values instead


of squares and square roots

∇f ≈ G x + G y
Gradient Operators
Æ The direction of the gradient vector
⎛ Gy ⎞
α ( x, y ) = tan −1 ⎜⎜ ⎟⎟
G
⎝ x⎠

Æ The direction of an edge at (x,y) is perpendicular to the


direction of the gradient vector at the point

The Gradient
Æ Robert cross-gradient operators
G x = ( z 9 − z 5 ) and G y = ( z 8 − z 6 )

[
∇f = ( z 9 − z 5 ) 2 + ( z 8 − z 6 ) 2 ] 1/ 2

∇f ≈ z 9 − z 5 + z8 − z 6

Æ Sobel Operator
∇f ≈ ( z7 + 2 z8 + z9 ) − ( z1 + 2 z2 + z3 )

+ ( z 3 + 2 z 6 + z 9 ) − ( z1 + 2 z 4 + z 7 )
Gradient Operator

⎡G x ⎤ ⎡( z 6 − z 5 ) ⎤
z1 z2 z3 ∇f = ⎢ ⎥ ≅ ⎢ ⎥
z4 z5 z6
G ( z
⎣ y⎦ ⎣ 8 5 ⎦ − z )
z7 z8 z9
[
∇ f ≅ ( z 6 − z 5 ) 2 + ( z8 − z 5 ) 2 ]
1/ 2

≅ | z 6 − z 5 | + | z8 − z 5 |

Gradient Operator
ÆRoberts cross-gradient

⎡G x ⎤ ⎡( z 9 − z 5 ) ⎤
z1 z2 z3 ∇f = ⎢ ⎥ ≅ ⎢ ⎥
G
⎣ ⎦y ⎣ ( z 8 − z 6 ) ⎦
z4 z5 z6
z7 z8 z9
[
∇ f ≅ ( z 9 − z 5 ) + ( z8 − z 6 )
2
]
2 1/ 2

≅ | z 9 − z 5 | + | z8 − z 6 |
Gradient Operator
ÆRobert cross-gradient filter masks

-1 0 ⎡G x ⎤ ⎡( z 9 − z 5 ) ⎤
∇f = ⎢ ⎥ ≅ ⎢ ⎥
G ( z
⎣ y⎦ ⎣ 8 6 ⎦ − z )
0 1

0 -1
[
∇ f ≅ ( z 9 − z 5 ) + ( z8 − z 6 )
2
]
2 1/ 2

≅ | z 9 − z 5 | + | z8 − z 6 |
1 0

Prewitt Operator
z1 z2 z3 -1 0 1 -1 -1 -1
z4 z5 z6 -1 0 1 0 0 0
z7 z8 z9 -1 0 1 1 1 1
Gx Gy

⎡Gx ⎤ ⎡( z3 + z6 + z9 ) − ( z1 + z 4 + z7 )⎤
∇f = ⎢ ⎥ ≅ ⎢ ⎥
G ( z
⎣ y⎦ ⎣ 7 8 9+ z + z ) − ( z1 + z 2 + z )
3 ⎦

∇f ≅ | G x | + | G y |
Sobel Operator
z1 z2 z3 -1 0 1 -1 -2 -1
z4 z5 z6 -2 0 2 0 0 0
z7 z8 z9 -1 0 1 1 2 1
Gx Gy

⎡Gx ⎤ ⎡( z3 + 2 z6 + z9 ) − ( z1 + 2 z 4 + z7 )⎤
∇f = ⎢ ⎥ ≅ ⎢ ⎥
G
⎣ y⎦ ⎣ 7( z + 2 z 8 + z 9 ) − ( z1 + 2 z 2 + z )
3 ⎦

∇f ≅ | G x | + | G y |

Various filter masks


Examples

edges by wall bricks, too detail !

Examples

Note that averaging caused the response of all edges to be weaker


Diagonal Edge Masks

Diagonal Edge
Laplacian
Æ The Laplacian is a second-order derivative
∂2 f ∂2 f
∇ f = 2 + 2
2

∂x ∂y
Æ Digital approximation

∇ 2 f = 4 z 5 − ( z 2 + z 4 + z 6 + z8 )
∇ 2 f = 8 z5 − ( z1 + z 2 + z3 + z 4 + z6 + z7 + z8 + z9 )

0 -1 0 -1 -1 -1
-1 4 -1 -1 8 -1
0 -1 0 -1 -1 -1

Laplacian
Æ TheLaplacian generally is not used in its original
form for edge detection for several reasons
Æ It is unacceptably sensitive to noise
Æ The magnitude of the Laplacian produces double
edges
Æ It is unable to detect edge direction
Æ The role of the Laplacian in segmentation
Æ finding the location of edge using its zero crossing
property
Æ judging whether a pixel is on the dark or light side of
an edge
Laplacian of Gaussian
ÆThe Laplacian is combined with smoothing
to find edges
Æ Gaussian function
⎛ r2 ⎞
h(r ) = − exp⎜⎜ − ⎟
2 ⎟ r 2 = x2 + y2
⎝ 2σ ⎠
Æ LoG(Laplacian of Gaussian) : Mexican hat
⎡r2 −σ 2 ⎤ ⎛ r2 ⎞
∇ h( r ) = − ⎢ ⎥ exp⎜⎜ − ⎟
2
2 ⎟
⎣ σ 4
⎦ ⎝ 2σ ⎠

LoG : Laplacian of Gaussian


Laplacian of Gaussian
Æ Meaning
Æ Gaussian function : smoothing, lowpass filter, noise
reduction
Æ Laplacian : highpass filter, abrupt change (edge)
detection
Æ It is of interest to note that neurophysiological
experiments carried out in the early 1980s
provide evidence that certain aspects of human
vision can be modeled mathematically in the
basic form of LoG function

Laplacian of Gaussian
Æ Gaussian function with a
standard deviation of five pixels
Æ 27x27 spatial smoothing
mask
Æ The mask was obtained by
sampling the Gaussian function
at equal intervals
Æ After smoothing we apply the
Laplacian mask
Æ Comparison
Æ The edges in the zero-crossing
image are thinner than the
gradient edges
Æ The edges determined by zero
crossings form numerous closed
loops (spaghetti effect:
drawback)
Æ The computation of zero
crossings presents a challenge
Edge Linking
Æ Edge detection Æ edge linking
Æ One of the simplest approaches for linking edge points is
to analyze the characteristics of pixels in a small
neighborhood
Æ All points that are similar according to a set of predefined
criteria are linked
Æ Two principal properties
Æ The strength of the gradient
Æ The direction of the gradient vector
∇f ( x, y ) − ∇f ( x0 , y0 ) ≤ E
α ( x, y ) − α ( x0 , y0 ) ≤ A
Æ The direction of the edge at (x,y) is perpendicular to the
direction of the gradient vector at that point

Edge Linking
Æ Given n points in an image, suppose that we want to find
subsets of these points that lie on straight lines
Æ One possible solution is to first find all lines determined
by ebery pair of points,
Æ then find all subsets of points that are close to particular
lines
Æ It involves finding n(n-1)/2 lines and then performing n x
n(n-1)/2 comparisons !
Æ Hough transform[1962]
Hough Transform[1962]
Æ Parameter space consideration
Æ Infinitely many lines pass through a point are represented
a line in the parameter space(ab-plane)
yi = axi + b b = − xi a + yi
Æ When the line associated with ( xi , yi ) intersects the line
associated with ( x j , y j ) at (a' , b' ), a' is the slope and
b' the intercept of the line determined by the two points

Hough transform
Æ The Hough transform subdivides the parameter space into so-called
accumulator cells
Æ These cells are set to zero
Æ For every point (xk, yk) , we let the parameter a equal each of the
allowed subdivision values on the a-axis and solve for the
corresponding b
Æ The resulting b’s are then rounded off to the nearest allowed value in
the b-axis
Æ If a choice of ap results in solution bq, we let A(p,q)=A(p,q)+1
Æ At the end, a value of Q in A(i,j) corresponds to Q points in the xy-
plane lying on the line y=aix+bj

b j = − xk ai + yk
Hough transform
Æ Ifthere are K increments in the a axis, K computation is
needed for every point Æ nK computation for n image
points (linear)
Æ There is a problem when the slope approaches infinity
(vertical line)

Hough transform
Æ One solution: to use the following representation
x cosθ + y sin θ = ρ
Æ The loci are sinusoidal curves in the ρθ -plane
Æ Q collinear points lying on a line x cos θ j + y sin θ j = ρ i
yield Q sinusoidal curves that intersect at ( ρ i , θ j )
Hough transform
Æ Aerial infrared image
Æ Thresholded gradient image using Sobel operators
Æ Pixels are linked
Æ they belongs to one of the three accumulator cells with highest count
Æ No gaps were longer than five pixels

Thresholding
Æ Global Thresholding
Æ Apply the same threshold to the whole image
Æ Local Thresholding
Æ The threshold depends on local property such as local average
Æ Dynamic(adaptive) thresholding
Æ The threshold depends on the spatial coordinates
Æ The problem is how to select the threshold automatically!
Global Thresholding
Æ It
is successful in highly controlled environment
Æ One of the areas is in industrial inspection application,
where control of the illumination usually is feasible

Global Thresholding
Æ Automatic threshold selection
1. Select an initial estimate for T
2. Segment the image using T,
which produce two groups, G1, G2
3. Compute the average gray level
values μ1 and μ 2 for the pixels in
regions G1 and G2
4. Compute a new threshold value:
1
T= ( μ1 + μ 2 )
2
5. Repeat step 2 through 4 until the
difference in T in successive
iterations is smaller than a
predefined parameter T0
Basic Adaptive Thresholding
Æ divide the image into subimages, then thresholding

Basic Adaptive Thresholding


Optimal Global and Adaptive Thresholding
Æ Method for estimating thresholds that produce the
minimum average segmentation error
Æ Suppose that an image contains only two principal gray-
level regions
Æ The histogram may be considered an estimate of the
probability density function(PDF) of gray level values
Æ This overall density function is the sum or mixture of two
densities, one for the light and the other for the dark
regions
Æ The mixture parameters are proportional to the relative
areas of the dark and light regions
Æ If the form of the densities is known or assumed, it is
possible to determine an optimal threshold

Optimal Global and Adaptive Thresholding


Æ The mixture probability density function is
p( z ) = P1 p1 ( z ) + P2 p2 ( z )
Æ P1 and P2 are the probabilities of occurrence of the two classes of
pixels
Æ P1 is the probability (a number) that a random pixel with value Z is an
object pixel
Æ Any given pixel belongs either to an object or to the background
P1 + P2 = 1
Æ The main objective is to select the value of T that minimizes the
average error in making the decisions that a given pixel belongs to
an object or to the background
Optimal Global and Adaptive Thresholding
Æ The probability of errorneously classifying a background point as an
object point is T
E1 (T ) = ∫ p2 ( z )dz
−∞
Æ Similarly, ∞
E2 (T ) = ∫ p1 ( z )dz
T

Æ Then the overall probability of error is


E (T ) = P2 E1 (T ) + P1 E2 (T )
Æ To find the threshold value for minimal error requires differentiating
E(T) with respect to T and equating the result to 0
Æ The result is
P1 p1 (T ) = P2 p2 (T )
Æ Note that if P1 = P2 then the optimum threshold is where the curves
for p1 ( z ) and p2 ( z ) intersect

Optimal Global and Adaptive Thresholding


Æ If the PDFs are Gaussians such as G ( μ1 , σ 1 ), G ( μ 2 , σ 2 )
and the variances are equal, σ 2 = σ 12 = σ 22
then the threshold is given
μ1 + μ 2 σ2 ⎛P ⎞
T= + ln⎜⎜ 2 ⎟⎟
2 μ1 − μ 2 ⎝ P1 ⎠

Æ If P1 = P2, the optimal threshold is the average of the means


Use of Boundary Characteristics
Æ The chance of selecting a “good” threshold are enhanced
considerably if the histogram peaks are tall, narrow, symmetric, and
separated by deep valleys
Æ One approach for improving the shape of histograms is to consider
only those pixels that lie on or near the edges between objects and
the background
Æ Separate an object and the background around a boundary using
gradient and Laplacian
⎧ 0 if ∇f < T

s ( x, y ) = ⎨+ if ∇f ≥ T and ∇ 2 f ≥ 0
⎪− f ∇f ≥ T and ∇ 2 f < 0

Æ (…) (-,+) (0 or +) (+,-) (…) structure

0 1 0 Labeling

Use of Boundary Characteristics


Gradient & Laplacian(Revisited)

Gradient & Laplacian(Revisited)


ÆGradient:
⎡ ∂f ⎤
⎡G x ⎤ ⎢ ⎥
∇f = ⎢ ⎥ = ⎢ ∂∂fx ⎥
⎣G y ⎦ ⎢ ⎥
⎢⎣ ∂y ⎥⎦

∇f = mag (∇f ) ≅| Gx | + | G y |

ÆLaplacian:
∂2 f ∂2 f
∇ f = 2 + 2
2

∂x ∂y
Segmentation by local thresholding

Region-Based Segmentation
Æ Segmentation is a process that partitions R into n
subregions, R1, R2,..., Rn, such that
n
(a) U Ri = R (complete)
i =1
(b) Ri is a connected region
(c) Ri I R j = φ for all i and j , i ≠ j (disjoint)
(d ) P( Ri ) = TRUE for all i
(e) P( Ri U R j ) = FALSE for i ≠ j
Æ P( Ri ) is a logical predicate which represents criterion
that segments the regions
Region Growing
Æ Region growing is a procedure that groups pixels or subregions into
larger regions based on predefined criteria
Æ The basic approach is to start with a set of ‘Seed’ points and from
these grow regions by appending to each seed those neighboring
pixels that have properties similar to the seed
Æ Selections of ‘Seed’ point and similarity criteria are the primary
problem
Æ Another problem in region growing is the formulation of a stopping
rule
Æ ex) P: diff<3 P: diff<8
0 0 5 6 7 a a b b b a a a a a
1 1 5 8 7 a a b b b a a a a a
0 1 6 7 7 a a b b b a a a a a
2 0 7 6 6 a a b b b a a a a a
0 1 5 6 5 a a b b b a a a a a

Region Growing
Region Splitting and Merging
Æ An alternative is to subdivide an image initially into a set
of arbitrary, disjointed regions and then merge and/or split
the regions to satisfy the conditions
Æ Algorithm
(1) We start with the entire region R
(2) If P(Ri)=FALSE, split into four disjoint quadrants
(3) Merge any adjacent regions Rj , Rk for which P(Rj U Rk)=TRUE
(4) Stop when no further merging or splitting is possible

Region Splitting and Merging


Region Splitting and Merging
Æ P(Rj)=TRUE
if at least 80% of the pixels in Rj have the property z j − mi ≤ 2σ i
where z j is the gray level of the jth pixel, mi is the mean gray level of
region Rj, and σ i is the standard deviation of the gray levels

The Use of Motion


Æ Motion is a powerful cue used by humans and many animals to
extract objects of interest from a background
Æ One of the simplest approaches for detecting changes between
two image frames is to compare them pixel by pixel
Æ A difference image
⎧1 if f ( x, y, ti ) − f ( x, y, t j ) > T
d ij ( x, y ) = ⎨
⎩0 otherwise
Æ It resulted from object motion
Æ This approach is applicable only if the two images are registered
spatially and if the illumination is relatively constant within the
bounds established by T
Æ Practically 1-valued entries often arise as a result of noise
Æ They are usually isolated points
Æ ignore small regions, accumulation, filtering
Building a Static Reference Image
Digital Image Processing

1-Segmentation (Cont.)
2-Color Image Processing
Region-Oriented Segmentation
• Basic formulation

is a connected region
Region Growing by Pixel Aggregation
• Region growing is a procedure that groups
pixels or sub-regions into larger regions.
• Simplest approach is pixel aggregation
• Pixel aggregation needs a seed point
Region Growing Problems
• Selecting initial seed
• Selecting suitable properties for including
points
– Example: In military applications using infra red
images, the target of interest is slightly hotter than
its environment
Example : Weld defects
Region Splitting and Merging
• Divide the image into a set arbitrary disjoint
regions.
• Merge/split the regions
Quad-Tree
The Use of Motion in Segmentation
• Compare two image taken at time t1 and t2
pixel by pixel (difference image)
• Non-zero parts of the difference image
corresponds to the non-stationary objects

• dij(x,y)= 1 if |f(x,y,t1) – f(x,y,t2)| > θ


0 otherwise
Accumulating Differences
• A difference image may contain isolated
entries that are the result of the noise
• Thresholded connectivity analysis can remove
these points
• Accumulating difference images can also
remove the isolated points
Color Image Processing
• Color fundamentals
Visible Wavelength
Absorption of light by human eye
Red, Green, Blue Color Cube
RGB Color Cube
Composing Color Components
YIQ Color Model
• YIQ is the color space used by the NTSC color TV
system
• The Y component represents the luma
information, and is the only component used by
black-and-white television receivers
• I and Q represent the chrominance information
• For example, applying a histogram equalization to
a color image is done by Y component only
YIQ Color Model
HSI Color Model
Conversion from RGB to HSI
Pseudo-Color Image Processing
Pseudo-Color Image Processing
Pseudo-Color Image Processing
Enhancement using HSI Model
Enhancement using HSI Model
Assignment
An image is composed of small non-overlapping
blobs of mean gray level m=150 and variance
σ2=400. All the blobs occupy approximately
20% of the image area. Propose a technique
based on thresholding fro segmenting the
blobs out of the image.
Potential Term Project Topics
• Segmentation using Watershed algorithm
Potential Term Project Topics
• Segmentation Using Level Sets
Image Processing : Feature
Extraction

CS-293

Guide: Prof G. Sivakumar

Compiled by:
Siddharth Dhakad
Chirag Sethi
Nisarg Shah
Problem Definition
• Image processing is a field of signal
processing in which input and output signals
are both images (2D matrices).

• Feature extraction involves simplifying the


amount of resources required to describe a
large set of data accurately.

• Our project studies and implements various


algorithms on feature extractions.
The following Feature Extraction techniques
were implemented

• Edge Detection:
– Sobel’s algorithm
– Canny’s algorithm

• Circle Detection:
– Hough Transform

• Line Detection:
– Hough Transform

• Corner Detection:
– Trajkovic’s 8-neighbour algorithm
Solution Design &
Implementation
Image

• The images we handle are RGB type.

• Each pixel is a 32 bit integer.

• We have implemented a new data type


for handling images called Picture.
Picture Class
• Constructors
– From Picture
– From a 2D array
– From a filename

• Saving & Loading images

• Grayscale

• Crop
Picture Class

FILE

2D
SHOW
ARRAY
IMAGE

IMAGE

EDIT
GRAYSCALE
PIXELS

CROP
Edge Detection
• Edge detection is a terminology which aim at
identifying points in a digital image at which the
image brightness changes sharply or more
formally has discontinuities.

• Edge Detection algorithms are broadly


classified as
– First order
– Higher order
Original (Input) Image
Sobel Edge Detector

Input Image

Gray-Scaled Image

Masking

Threshold

Edge Detected
Canny Edge Detector
Input Image Gray-Scaled Image

Masking Noise Reduction

Non-maxima Edge Detected


Suppression Threshold
• For reducing noise, we used Gaussian Filter
(Blurring Algorithm).

• On edge detected by first order detector, we


used an algorithm called Non-maximal
Suppression to have single/thin edges.

• After that, we used Stack data structure for


path traversal for finding continuous edges.
Manual Threshold Automatic Threshold
Original Image Sobel

Canny Manual Canny Automatic


Canny v/s Sobel
• Thin Edges • Thick Edges

• Noise reduction • No blurring

• Complete path • Discrete pixels

• High adjustability • Low adjustability


Line & Circle Detection

Input Image Edge Detection Hough Transform

Detected Threshold
Path Traversal
Lines/Circles

In Circle Detection, we also included taking range of radius of circles


to be detected as input to make the algorithm run faster.
Original Image Line Hough Transform

Original Image Circle Hough Transform


Corner Detection

Input Image
Original Image

Cornerness of
each pixel

Threshold

Corner Detected Corner


Detected
Threshold Selection
• Manual:
– User can set high-low thresholds for each
operation performed during the algorithm.

• Automatic:
– By experimentation, we have found a
heuristic to select a suitable threshold for
any input image.
The Hard Part
• Selecting suitable threshold for any input
image

• Deciding the proper class hierarchy for


modular implementation

• Implementing path traversal and non-


maximal suppression algorithms
Results & Analysis
(Applied to standard
test image)
Original Image Standard Canny Output Our Canny Output

Standard Sobel Our Sobel


Output Output
Original Image Standard Canny Output

Our Canny Output Automatic Canny Output Our Sobel Output


Original Image Standard Output

Our Output
Original Image Standard Output

Our Output
Original Image Standard Output

Our Output
Future Possibilities
• Generalized Curve Detection
• Higher Order Edge Detection
• Some more shape based feature
detection
• Optimizations in current algorithms
• Handling large size images
• Pattern recognition
• Face recognition
What we learnt
• Feature Extraction Algorithms
• Limitations of algorithms when applied to
real life problems
– Image Size
– Selecting Threshold
– Noise
• Handling Images
– Image types : RGB, ARGB, Raster, Vector
• Java/Swing
• Time Management
• Working as a team
COMS30121 | Department of Computer Science | University of Bristol

Image Processing &


Computer Vision
Lecturer: Dr Tilo Burghardt ( mailto: tilo@cs.bris.ac.uk )
Web: http://www.cs.bris.ac.uk/Teaching/Resources/COMS30121

LECTURE 3:
EDGE DETECTION
AND BEYOND

Dr Tilo Burghardt | Image Processing & Computer Vision , COMS30121 | Dept of Computer Science, University of Bristol | L1 - Slide1/15
Recap – Edge Detection by Filtering

• Detection of Edges
by using Edge-like
Æ
Filter Kernels

• Roberts, Kirsch,
Prewitt and Sobel Operators

• Estimation of
Gradients

• Considering Noise…

Dr Tilo Burghardt | Image Processing & Computer Vision , COMS30121 | Dept of Computer Science, University of Bristol | L1 - Slide2/15
Second Derivative Methods

• Derivative has extremum at the edge

• Second derivative is zero there!

Æ Easier and more precise to detect

• However, second derivative is


extremely sensitive to noise

Æ Smooth image first


to reduce the noise

Dr Tilo Burghardt | Image Processing & Computer Vision , COMS30121 | Dept of Computer Science, University of Bristol | L1 - Slide3/15
Laplacian Operator

• Also known as Marr-Hildreth operator


• Locates edges by looking for zero-crossings
• Big response to noise
• Find zero crossings
Pierre-Simon Laplace

Dr Tilo Burghardt | Image Processing & Computer Vision , COMS30121 | Dept of Computer Science, University of Bristol | L1 - Slide4/15
Example of Laplacian Filtering

original after Laplacian filtering

Dr Tilo Burghardt | Image Processing & Computer Vision , COMS30121 | Dept of Computer Science, University of Bristol | L1 - Slide5/15
Laplacian of Gaussian (LoG)

Dr Tilo Burghardt | Image Processing & Computer Vision , COMS30121 | Dept of Computer Science, University of Bristol | L1 - Slide6/15
Difference of Gaussian (DoG)

Dr Tilo Burghardt | Image Processing & Computer Vision , COMS30121 | Dept of Computer Science, University of Bristol | L1 - Slide7/15
Scale in Image Processing

• Localised Processing Æ Scale of the localisation is crucial!


• Processing at multiple scales: Scale-space Filtering
• Hierarchical Analysis Æ Gaussian and Laplacian Pyramids

Dr Tilo Burghardt | Image Processing & Computer Vision , COMS30121 | Dept of Computer Science, University of Bristol | L1 - Slide8/15
Scale Space

Dr Tilo Burghardt | Image Processing & Computer Vision , COMS30121 | Dept of Computer Science, University of Bristol | L1 - Slide9/15
Diffusion as an Operator

Dr Tilo Burghardt | Image Processing & Computer Vision , COMS30121 | Dept of Computer Science, University of Bristol | L1 - Slide10/15
Scale Space Generation via Diffusion

Dr Tilo Burghardt | Image Processing & Computer Vision , COMS30121 | Dept of Computer Science, University of Bristol | L1 - Slide11/15
Advanced Diffusion Techniques

Dr Tilo Burghardt | Image Processing & Computer Vision , COMS30121 | Dept of Computer Science, University of Bristol | L1 - Slide12/15
Canny Edge Detection

• Gaussian Smoothing
• Gradient Estimation
• Non-maximal Suppression
• Thresholding with Hysteresis
• Feature Synthesis

Dr Tilo Burghardt | Image Processing & Computer Vision , COMS30121 | Dept of Computer Science, University of Bristol | L1 - Slide13/15
Approaches to Thresholding Edges

Dr Tilo Burghardt | Image Processing & Computer Vision , COMS30121 | Dept of Computer Science, University of Bristol | L1 - Slide14/15
Outlook

• Next time in Lecture 4 …

How can we segment images?

Dr Tilo Burghardt | Image Processing & Computer Vision , COMS30121 | Dept of Computer Science, University of Bristol | L1 - Slide15/15

You might also like