You are on page 1of 12

Detection of Discontinuities

• Line detection: If each mask is moved around an


image it would respond more strongly to lines in the
Image Processing mentioned direction.

Chapter 10
Image Segmentation

Image Segmentation Detection of Discontinuities


• An important step in image analysis is to segment • There are 3 basic types of discontinuities in digital
the image. images:
• Segmentation: subdivides the image into its 1. Point
constituent parts or objects. 2. Line
• Autonomous segmentation is one of the most 3. Edges.
difficult tasks in image processing.
9
R = ∑ wi zi
• Segmentation algorithms for monochrome images
generally are based on two basic properties of gray- Mask:
i =1
level values:
1. Discontinuity 2. Similarity

2 5

Image Segmentation Detection of Discontinuities


• Discontinuity: the image is partitioned based on • Point detection: detect an isolated point
abrupt changes in gray level.
• Similarity: partition an image into regions that are R ≥T
similar
– Main approaches are thresholding, region growing
and region splitting and merging.

3 6

1
Edge detection
• The magnitude of the first derivative can be used to
detect an edge
• The sign (zero crossing) of the second derivative can
be used to detect an edge.
• The same idea can be extended into 2-D. 2-D
derivatives should be used.
• The magnitude of the gradient and sign of the
Laplacian are used.

7 10

Edge detection
• Edge: boundary between two regions with relatively
distinct gray levels.

8 11

Edge detection Gradient Operator


• Basic idea: computation of a local derivative operator.
⎡ ∂f ⎤
⎡Gx ⎤ ⎢ ∂x ⎥
Gradient ∇f = ⎢ ⎥ = ⎢ ⎥
⎣G y ⎦ ⎢ ∂f ⎥
⎣⎢ ∂y ⎦⎥
Gradient magnitude

∇f = mag (∇f ) = (G x
2
+ Gy 2 ) ∇f ≈ Gx + G y

Gradient direction
Gy
α ( x, y ) = tan −1 ( )
Gx

9 12

2
13 16

14 17

Laplacian
• Laplacian in its original form is not used for edge
detection because:
1. It is very sensitive to noise
2. It’s magnitude produces double edges
3. Unable to detect the direction of an edge.
• To solve the first problem, the image is low-pass
filtered before using the Laplacian operator.

f(x,y) h(x,y) ∇2 g(x,y)

15 18

3
Laplacian
∂ f ∂ f
2 2
∇2 f = +
∂x 2 ∂y 2
8
∇ 2 f = 8 z5 − ∑ zi
i =1
∇ 2 f = 4 z5 − ( z2 + z4 + z6 + z8 )

19 22

Laplacian of Gaussian (LoG)


Convolution: g ( x, y ) = f ( x, y )* ∇ 2 h( x, y )
x2 + y2
Gaussian function: h( x, y ) = exp(− )
2σ 2
r 2 = x2 + y 2
r2 −σ 2 r2
Second derivative: ∇ 2 h(r ) = ( ) exp(−
)
σ 4
2σ 2
• Cross section of ∇ 2 h has a Mexican hat shape.
• The average ∇ 2 h is zero. The average of constant image
convolved with ∇ 2 h is also zero.
• We will have negative pixel values in the result.

20 23

Laplacian Edge linking and Boundary Detection


• To solve the problem of double edges, zero crossing
of the output of Laplacian operator is used.
• The output of discontinuity detection stage seldom
characterizes a boundary completely.
• This is because of noise, breaks in the boundary and
other effects.
• Edge detection algorithms typically are followed by
linking and boundary detection procedures.
• These procedures assemble edge pixels into
meaningful boundaries.

21 24

4
Edge linking and Boundary Detection Hough transform
• (amin,amax): expected range of slope
• All the points that are similar are linked forming a
• (bmin,bmax): expected range of intercepts
boundary of pixels.
• A(i,j): the number of points in the cell at coordinates (i,j) in
• Two principle properties used for establishing the ab plane.
similarity of edge pixels in this kind of analysis are:
For every point in the image
1. The strength of the response of the gradient
plane we let the value of a
plane,
operator used to produce the edge pixels equal each of the allowed
2. The direction of the gradient subdivisions and find the
corresponding b from
∇f ( x, y ) − ∇f ( x0 + y0 ) ≤ E b= yi-axi If for ap we get bq
the A(p,q) is incremented.
α ( x, y ) − α ( x0 , y0 ) < A
25 28

Hough transform
• The cell with the largest value shows the parameters
of the line that contains the maximum number of
points.
• Problem with this method: a approaches infinity as
the line gets perpendicular to the x axis.
• Solution: use the representation of the line as:
x cosθ + y sin θ = ρ

26 29

Hough Transform Hough transform


• (xi,yi): all the lines passing this point yi=axi+b
• b= yi-axi : point (xi,yi) maps to a single line in ab plane.
• A point in xy plane is mapped into a sinusoidal curve
in ρθ plane.
• Another point (xj,yj) also maps to a single line in ab plane
b= yj-axj
• a’ and b’ are the slope and intercept of the line containing
both ((xi,yyi) and ((xj,yyj)).

27 30

5
Thresholding
• Single threshold: points with f(x,y)>T belong to object;
other points belong to background.
• Multiple thresholds: points with f(x,y)>T2 belong to
object; points with f(x,y)<T1 belong to bakground.

31 34

Hough transform Thresholding


• Hough transform is applicable to any function of the • Threshold in general can be calculated as:
form g(v,c)=0, where v is the vector of coordinates T=T(x,y,p(x,y),f(x,y))
and c is the vector of coefficients. f(x,y): gray level at (x,y)
• Exp: ( x − c1 ) 2 + ( y − c2 ) 2 = c32 p(x,y): some local property of the point (x,y) (e.g., the
• 3 parameters (c1,c2,c3), 3-D parameter space, cube average gray level of a neighborhood centered on (x,y).
lik cells,
like ll accumulatorsl t off th the fform A(i
A(i,j,k).
j k)
• Procedure: T depends only on f(x,y): global threshold
1. Increment c1 and c2 T depends on f(x,y) and p(x,y): local threshold
2. Solve for c3 T depends on f(x,y) and p(x,y) and x,y : dynamic threshold
3. Update the accumulator associated with (c1,c2,c3)

32 35

Thresholding Thresholding

• Thresholding is one of the most important


approaches to image segmentation.
• Gray level histogram of an image f(x,y) composed
of a light object on a dark background.
• To
T extract
t t the
th object:
bj t select
l t a threshold
th h ld T that
th t
separates the gray levels of the background and
the object.

33 36

6
Thresholding Basic Global Thresholding

MR brain image (top left), its


histogram (bottom) and the
segmented image (top right)
using a threshold T=12 at the
first major valley point in the
histogram.

37 40

Thresholding Basic Adaptive (Local) Thresholding

Two segmented MR brain


images using a gray value
threshold T=166 (top right)
and T=225 (bottom)

38 41

Basic Global Thresholding Optimal Global Thresholding


1. Select an initial estimate for T
2. Segment the image using T. This will produce two
group of pixels G1 (with gray level greater than T)
and G2 (with gray level less than T)
p average
3. Compute g y level values μ1 and μ2 for
g gray
pixels in regions G1 and G2 p ( z ) = P1 ⋅ p1 ( z ) + P2 ⋅ p2 ( z )
4. Compute a new threshold: T=(μ1+ μ2)/2
5. Repeat step 2 through 4 until the difference in T in P1 + P2 = 1
successive iterations is smaller than a predefined Problem: how to optimally determine T to minimize the
value segmentation error?

39 42

7
Optimal Global Thresholding Region Growing
T
Error 1: E1 (T ) = ∫ p2 ( z )dz
−∞
∞ • Pixel aggregation: starts with a set of seed point and
Error 2: E2 (T ) = ∫ p1 ( z )dz from these grows regions by appending to each seed
T
point those neighboring pixels that have similar
T t l error:
Total E (T ) = P1 E2 (T ) + P2 E1 (T ) properties
i (e.g.,
( gray-level,
l l texture, color).
l )

Goal: what’s the value of T to minimize E(T)?

Result: P1 p1 (T ) = P2 p2 (T )

43 46

Optimal Global Thresholding: Gaussian PDFs Region Growing


P1 ( z − μ1 ) 2 P2 ( z − μ2 )2
p( z ) = exp(− )+ exp(− )
2πσ 1 2σ 1
2
2πσ 2 2σ 22

Solution: AT 2 + BT + C = 0
A = σ 12 − σ 22
Center Pixel

B = 2( μ1σ 22 − μ2σ 12 ) Pixels satisfying the similarity criterion


Pixels unsatisfying the criterion

C = σ 12 μ22 − σ 22 μ12 + 2σ 12 2σ 22 ln(σ 2 P1 / σ 1P2 ) 3x3 neighborhood


Segmented region 5x5 neighborhood
7x7 neighborhood

44 47

Region Based Segmentation Region Growing


• Let R represent the entire image. Segmentation is a
process that partitions R into n subregions
R1,R2,…,Rn such that:
n
a) ∪ Ri = R
i =1

b) R i is a connected region.
c) R i ∩ R j = φ
d) P(R i ) = True
A T-2 weighted MR brain image (left) and the segmented
e) P(R i ∪ R j ) = False ventricles (right) using the region-growing method.

45 48

8
Region growing Region Splitting and Merging
• Sub-divide an image into a set of disjoint regions
and then merge and/or split the regions in an attempt
• Problems: to satisfy the condition (P).
1. Selection of initial seeds that properly represent
regions of interest
2 Selection of suitable
2. s itable properties
3. Formulation of a stopping rule.

49 52

Seeded Region Growing Region Splitting and Merging


• Procedure:
1. Split into 4 disjoint quadrants any region Ri where
P(Ri)= False.
2. Merge any adjacent regions Rj and Rk for which
P(Rj U Rk))= True.
True
3. Stop when no further merging or splitting is
possible.

50 53

Region Growing in a Diffusion Weighted Image Region Splitting and Merging

51 54

9
Mathematical Morphology Example of Erode Function
• Mathematical morphology involves a convolution-like
process using various shaped kernels, called structuring
elements
• The structuring elements are mostly symmetric: squares,
rectangles, and circles
• Most common morphological operations are
– Erosion
– Dilation
– Open
– Close
• The operations can be applied iteratively in selected order to
effect a powerful process
Input image Eroded image

55 58

Erosion Functions Erosion Example


• Erosion function is a reduction operator.
• It removes noise and other small objects, breaks thin
connections between objects, removes an outside
layer from larger objects, and increases the size of
holes within an object
o bbinary
• For a y images,
ages, aanyy ppixel
e tthat
at iss 1 and
a d has
as a
neighbor that is 0, is set to 0
• The minimum function is the equivalence of an
erosion
• The neighbors considered are defined by the
structuring element
Input image Eroded image

56 59

Illustration of Erosion Function Dilation Function


• The dilation function is an enlargement operator, the reverse
of erosion
• For a binary data set, any 0 pixel that has a 1 neighbor, where
the neighborhood is defined by the structuring element, is set
to 1
• For gray scale data, the dilation is a maximum function
• The dilation fills small holes and cracks and adds layers to
objects in a binary image

Erosion with a 3x3 square structuring element

57 60

10
Example of Dilation Example of Open Operation

Input image Dilated image Input image Opened image

61 64

Dilated Image Example of Open Operation

Input image Dilated image


Input image Opened image

62 65

Erosion – Dilation Functions Example of Close Operation


• Erosion and dilation are essentially inverse
operations, they are often applied successively to an
image volume
• An erosion followed by a dilation is called an open
• A morphological open will delete small objects and
break thin connections without loss of surface layers
• A dilation followed by an erosion is called close
• The close operation fills small holes and cracks in an
object and tends to smooth the border of an object
Input image Closed image

63 66

11
Example of Close Operation Example of A Snake Algorithm

Input image Closed image Initial contour in green, yellow Final contour converged
is intermediate contour in 25 iterations
67 70

An Automated Segmentation Active Contour with Level-Set Method

(a)original image, (b) thresholding, (c) erosion, (d) dilation,


(e) closing, (f) mask rendering, (g) volume rendering

68 71

Active Contours (Snakes)


• Segmenting an object in an image with active
contours involves minimizing a cost function based
on certain properties of the desired object boundary
and contrast in the image
• Smoothness of the boundary curve and local
gradients in the image are usually considered End of Lecture
• Snake algorithms search the region about the current
point and iteratively adjust the points of the boundary
until an optimal, low cost boundary is found
• It may get caught in a local minimum (initial guess)

69 72

12

You might also like