Digital Image Processing
Lecture 6
Image Segmentation
Segmentation
Image segmentation is the process of partitioning the
digital image into multiple regions
Segmentation accuracy determines the eventual success
or failure of the following image processing tasks:
Pattern recognition
Computer Aided Diagnosis systems
For this reason, considerable care should be maintained
to segmentation procedure
Region/Segment
 What is a region or a segment?
 It is an aggregation of pixels
 Properties like gray level, color, texture, or shape are used to build groups
of regions having a particular meaning.
 In mathematical sense the segmentation of the image I, which is a set of
pixels, is the partition of I into n disjoint sets R1,R2, . . . , Rn, called
segments or regions such that their union of all regions equals I.
I= R1 U R2 U….. U Rn
 Image segmentation is based on either one of two gray level intensity
properties:
 Gray level discontinuity (e.g. edge detection)
 Gray level similarity (e.g. thresholding)
Detection of Discontinuity
The most common method to detect discontinuity in an
image is by running a spatial mask of specific width
and number of coefficients
The window mask is multiplied by the original image
pixels and the sum of product is calculated
Discontinuity could be applied on:
An isolated point
A line
An edge
Discontinuity: Point Detection
An isolated point: it is a point (several aggregate of pixels)
whose intensity differs significantly from the its homogeneous
background.
The idea for isolated point detection consists of assuming a mask
with equal coefficients everywhere except at the center, where the
coefficient has a higher value with opposite sign
The center of the mask is moved from one pixel to another within
an image.
At each location, the sum of the product of the mask coefficients
and the pixels gray levels is calculated.
An isolated point is detected when this sum is larger than a given
threshold
Discontinuity: Point Detection
Discontinuity: Line Detection
For line detection, the same idea is performed but with
different masks
Could detect horizontal, vertical, or ‘m’ slope lines
The preferred direction in the mask is weighted by a
different weight (larger value and opposite sign)
The main disadvantage in this method is that only
strong responses (lines having large differences than the
background) could be detected.
Discontinuity: Line Detection
Discontinuity: Edge Detection
Edge detection is the most common approach for
detecting meaningful discontinuities in gray
level.
An edge: is the boundary between two regions
with relatively distinct gray level properties.
An edge could be ideal or blurred
Blurred edges need sophisticated algorithms to
be detected
Edge Detection
Edge detection
• Goal: Identify sudden changes
(discontinuities) in an image
Intuitively, most semantic and shape
information from the image can be encoded in
the edges
More compact than pixels
• Ideal: artist’s line drawing (but artist is
also using object-level knowledge)
Characterizing edges
• An edge is a place of rapid change in the image intensity
function
image
intensity function
(along horizontal scanline) first derivative
edges correspond to
extrema of derivative
Discontinuity: Edge Detection
If the regions are sufficiently homogeneous, edge
detection could be performed by the computation of a
derivative operator, where the intensity variation is
plotted then the first derivative is used to detect the
presence of an edge
For non- homogeneous regions, a technique based
on gradient function should be used, as the maximum
rate of change of image intensity is in direction of
gradient.
The gradient points in the direction of most rapid increase in intensity
Image gradient
The gradient of an image:
The gradient direction is given by
• how does this relate to the direction of the edge?
The edge strength is given by the gradient magnitude
'( ) ( 1) ( )
f
f x f x f x
x

   

15
Discontinuity: Edge Detection
The magnitude and the direction of the gradient
should be calculated at each pixel:
𝑮 𝒇 𝒙, 𝒚 =
𝝏𝒇
𝝏𝒙
𝟐
+
𝝏𝒇
𝝏𝒚
𝟐
𝜶 𝒙, 𝒚 = 𝐭𝐚𝐧−𝟏
𝝏𝒇 𝝏𝒙
𝝏𝒇 𝝏𝒚
where G is the magnitude of the gradient and α is its direction. The
edge is then found by linking all points in the direction calculated.
Finite difference filters
• Other approximations of derivative filters exist:
Discontinuity: Edge Detection
Edge detection algorithms face several
problems:
Noise
Edge break due to illumination problems
Any other effect that causes discontinuity
Effects of noise
Consider a single row or column of the image
Plotting intensity as a function of position gives a signal
Where is the edge?
Effects of noise
• Finite difference filters respond strongly to noise
Image noise results in pixels that look very different from
their neighbors
Generally, the larger the noise the stronger the response
• What is to be done?
Smoothing the image should help, by forcing pixels
different to their neighbors (=noise pixels?) to look more like
neighbors
Solution: smooth first
• To find edges, look for peaks in )
( g
f
dx
d

f
g
f * g
)
( g
f
dx
d

• Differentiation is convolution, and convolution is associative:
• This saves us one operation:
g
dx
d
f
g
f
dx
d


 )
(
Derivative theorem of convolution
g
dx
d
f 
f
g
dx
d
Designing an edge detector
• Criteria for an “optimal” edge detector:
 Good detection: the optimal detector must minimize the probability of
false positives (detecting spurious edges caused by noise), as well as that
of false negatives (missing real edges)
 Good localization: the edges detected must be as close as possible to the
true edges
 Single response: the detector must return one point only for each true
edge point; that is, minimize the number of local maxima around the true
edge
Canny edge detector
• This is probably the most widely used edge
detector in computer vision
• Theoretical model: step-edges corrupted by
additive Gaussian noise
• Canny has shown that the first derivative of the
Gaussian closely approximates the operator that
optimizes the product of signal-to-noise ratio and
localization
Canny edge detector
1. Filter image (Smooth) with derivative of Gaussian
2. Find magnitude and orientation of gradient
3. Apply non-maximum suppression to the gradient magnitude image
 Thin multi-pixel wide “ridges” down to single pixel width
4. Use double thresholding and connectivity analysis to detect and
link edges (Linking and thresholding):
 Define two thresholds: low and high
 Use the high threshold to start edge curves and the low threshold to
continue them
 MATLAB: edge(image, ‘canny’)
Example
 original image (Lena)
Example
norm of the gradient
Example
thresholding
Example
thinning
(non-maximum suppression)
Non-maximum suppression
At q, we have a
maximum if the value is
larger than those at
both p and at r.
Interpolate to get these
values.
Assume the marked point
is an edge point. Then we
construct the tangent to
the edge curve (which is
normal to the gradient at
that point) and use this to
predict the next points
(here either r or s).
Edge linking
Discontinuity: Edge Linking 1
Edge Linking: becomes an important approach after edge
detection
How to link edges?
1. First define a small window (3x3) or (5x5)
2. The center of this window is a pixel defined as an edge (x0 ,y0 )
3. Check other pixels inside the window if considered as edges or not by
calculating the gradient at each
4. A pixel (x,y) is considered linked edge if:
1. |G(x,y)-G(x0 ,y0 )| < E
2. Θ(x,y) - Θ(x0 ,y0 ) < A
Where G is the magnitude of the gradient and Θ is the angle of the gradient
E and A are magnitude and phase thresholds respectively
Effect of  (Gaussian kernel spread/size)
Canny with Canny with
original
The choice of  depends on desired behavior
• large  detects large scale edges
• small  detects fine features
Edge detection is just the beginning…
image human segmentation gradient magnitude
35 Basic Edge Detection by Using First-Order Derivative
2 2
1
( )
The magnitude of
( , ) mag( )
The direction of
( , ) tan
The direction of the edge
-90
x
y
x y
x
y
f
g x
f grad f
f
g
y
f
M x y f g g
f
g
x y
g

 


 
 
  
 
   
  
 
 
 

 

   

 
  
 
 

36 Basic Edge Detection by Using First-Order Derivative
Edge normal: ( )
Edge unit normal: / mag( )
x
y
f
g x
f grad f
f
g
y
f f

 
 
  
 
   
  
 
 
 

 
 
In practice,sometimes the magnitude is approximated by
mag( )= + or mag( )=max | |,| |
f f f f
f f
x y x y
 
   
   
   
 
37
38
39
40
Advanced Techniques for Edge Detection
The Marr-Hildreth edge detector
2 2
2
2 2 2 2
2 2
2 2 2 2
2 2
2
2 2
2
2 2
2 2
2 2
2 2
2 2
4 2 4 2
2
( , ) , :space constant.
Laplacian of Gaussian (LoG)
( , ) ( , )
( , )
1 1
x y
x y x y
x y x y
G x y e
G x y G x y
G x y
x y
x y
e e
x y
x y
e e
x

 
 

 
   


 
 
 
 

 
  
 
   
   
 
   
 
   
   
   
   
   
   

2 2
2
2 2
2
4
x y
y
e 




 
 
 
 
41
42 Marr-Hildreth Algorithm
1. Filter the input image with an nxn Gaussian lowpass
filter. N is the smallest odd integer greater than or
equal to 6
2. Compute the Laplacian of the image resulting from
step1
3. Find the zero crossing of the image from step 2
 
2
( , ) ( , ) ( , )
g x y G x y f x y
 

Edge Linking Using Hough Transform
Effective method to solve linear segmentation problems
Assume the following segmentation problem:
A set of ‘n’ points are in a plane,
We want to determine the points that are linked together to form a
straight line
Solution1:
We will take a pair of points and form a straight line
Check the number of remaining points that are close to this line
This process is repeated for all possible pairs of points and each time the
rest of points are checked for being part of this proposed line
The line that has maximum number of points closer to it is the fittest
one
Edge Linking Using Hough Transform
What is the problem concerned with solution 1 ?
Large number of computations
For ‘n’ points, we have nC2
= n
2
=
n(n+1)
2
possible pairs to
form the proposed lines
Each case, we have to compare (n-2) points, if the proposed
line passes closer to them or not
The number of computations is then:
n(n+1)(n+2)
2
Large mathematical computations
Edge Linking Using Hough Transform
 Solution by means of Hough Method, Hough proposed the following model:
 Given that the equation of a straight line is: 𝒚 = 𝒂𝒙 + 𝒃 , “a” and “b” are the line parameters
 At any point (x1 ,y1), we can write the equation of all lines passing through it as:
𝑦1 = 𝑎𝑥1 + 𝑏 𝒐𝒓 𝑏 = −𝑎𝑥1 + 𝑦1
 We have got a linear equation between ‘a’ and ‘b’ that could be represented in another plane
called: “The Parameter Space”
 Thus each point (x,y) will be transformed into a straight line in the parameter space
 If two lines in the parameter space -representing the pair of points (x1 ,y1 ) and (x2 ,y2 ) -will
intersect at values (a, b)
 These values’ couple ‘a’ and ‘b’ are parameters of the straight line joining them in original space
 When all ‘n’ points are transformed into the parameter space domain, we will simply observe the
values of (a,b) where the most points’ cloud density occurs.
 These values for ‘a’ and ‘b’ are the required ones; and these points are linked to form the required
line
Hough Transform
Hough Transform
All lines passing in this crowded area are then inversely
transformed to obtain the original points passing via the linked line
with parameters (a,b)

Lecture 06 - image processingcourse1.pptx

  • 1.
  • 2.
    Segmentation Image segmentation isthe process of partitioning the digital image into multiple regions Segmentation accuracy determines the eventual success or failure of the following image processing tasks: Pattern recognition Computer Aided Diagnosis systems For this reason, considerable care should be maintained to segmentation procedure
  • 3.
    Region/Segment  What isa region or a segment?  It is an aggregation of pixels  Properties like gray level, color, texture, or shape are used to build groups of regions having a particular meaning.  In mathematical sense the segmentation of the image I, which is a set of pixels, is the partition of I into n disjoint sets R1,R2, . . . , Rn, called segments or regions such that their union of all regions equals I. I= R1 U R2 U….. U Rn  Image segmentation is based on either one of two gray level intensity properties:  Gray level discontinuity (e.g. edge detection)  Gray level similarity (e.g. thresholding)
  • 4.
    Detection of Discontinuity Themost common method to detect discontinuity in an image is by running a spatial mask of specific width and number of coefficients The window mask is multiplied by the original image pixels and the sum of product is calculated Discontinuity could be applied on: An isolated point A line An edge
  • 5.
    Discontinuity: Point Detection Anisolated point: it is a point (several aggregate of pixels) whose intensity differs significantly from the its homogeneous background. The idea for isolated point detection consists of assuming a mask with equal coefficients everywhere except at the center, where the coefficient has a higher value with opposite sign The center of the mask is moved from one pixel to another within an image. At each location, the sum of the product of the mask coefficients and the pixels gray levels is calculated. An isolated point is detected when this sum is larger than a given threshold
  • 6.
  • 7.
    Discontinuity: Line Detection Forline detection, the same idea is performed but with different masks Could detect horizontal, vertical, or ‘m’ slope lines The preferred direction in the mask is weighted by a different weight (larger value and opposite sign) The main disadvantage in this method is that only strong responses (lines having large differences than the background) could be detected.
  • 8.
  • 9.
    Discontinuity: Edge Detection Edgedetection is the most common approach for detecting meaningful discontinuities in gray level. An edge: is the boundary between two regions with relatively distinct gray level properties. An edge could be ideal or blurred Blurred edges need sophisticated algorithms to be detected
  • 10.
  • 11.
    Edge detection • Goal:Identify sudden changes (discontinuities) in an image Intuitively, most semantic and shape information from the image can be encoded in the edges More compact than pixels • Ideal: artist’s line drawing (but artist is also using object-level knowledge)
  • 12.
    Characterizing edges • Anedge is a place of rapid change in the image intensity function image intensity function (along horizontal scanline) first derivative edges correspond to extrema of derivative
  • 13.
    Discontinuity: Edge Detection Ifthe regions are sufficiently homogeneous, edge detection could be performed by the computation of a derivative operator, where the intensity variation is plotted then the first derivative is used to detect the presence of an edge For non- homogeneous regions, a technique based on gradient function should be used, as the maximum rate of change of image intensity is in direction of gradient.
  • 14.
    The gradient pointsin the direction of most rapid increase in intensity Image gradient The gradient of an image: The gradient direction is given by • how does this relate to the direction of the edge? The edge strength is given by the gradient magnitude '( ) ( 1) ( ) f f x f x f x x      
  • 15.
  • 16.
    Discontinuity: Edge Detection Themagnitude and the direction of the gradient should be calculated at each pixel: 𝑮 𝒇 𝒙, 𝒚 = 𝝏𝒇 𝝏𝒙 𝟐 + 𝝏𝒇 𝝏𝒚 𝟐 𝜶 𝒙, 𝒚 = 𝐭𝐚𝐧−𝟏 𝝏𝒇 𝝏𝒙 𝝏𝒇 𝝏𝒚 where G is the magnitude of the gradient and α is its direction. The edge is then found by linking all points in the direction calculated.
  • 17.
    Finite difference filters •Other approximations of derivative filters exist:
  • 18.
    Discontinuity: Edge Detection Edgedetection algorithms face several problems: Noise Edge break due to illumination problems Any other effect that causes discontinuity
  • 19.
    Effects of noise Considera single row or column of the image Plotting intensity as a function of position gives a signal Where is the edge?
  • 20.
    Effects of noise •Finite difference filters respond strongly to noise Image noise results in pixels that look very different from their neighbors Generally, the larger the noise the stronger the response • What is to be done? Smoothing the image should help, by forcing pixels different to their neighbors (=noise pixels?) to look more like neighbors
  • 21.
    Solution: smooth first •To find edges, look for peaks in ) ( g f dx d  f g f * g ) ( g f dx d 
  • 22.
    • Differentiation isconvolution, and convolution is associative: • This saves us one operation: g dx d f g f dx d    ) ( Derivative theorem of convolution g dx d f  f g dx d
  • 23.
    Designing an edgedetector • Criteria for an “optimal” edge detector:  Good detection: the optimal detector must minimize the probability of false positives (detecting spurious edges caused by noise), as well as that of false negatives (missing real edges)  Good localization: the edges detected must be as close as possible to the true edges  Single response: the detector must return one point only for each true edge point; that is, minimize the number of local maxima around the true edge
  • 24.
    Canny edge detector •This is probably the most widely used edge detector in computer vision • Theoretical model: step-edges corrupted by additive Gaussian noise • Canny has shown that the first derivative of the Gaussian closely approximates the operator that optimizes the product of signal-to-noise ratio and localization
  • 25.
    Canny edge detector 1.Filter image (Smooth) with derivative of Gaussian 2. Find magnitude and orientation of gradient 3. Apply non-maximum suppression to the gradient magnitude image  Thin multi-pixel wide “ridges” down to single pixel width 4. Use double thresholding and connectivity analysis to detect and link edges (Linking and thresholding):  Define two thresholds: low and high  Use the high threshold to start edge curves and the low threshold to continue them  MATLAB: edge(image, ‘canny’)
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
    Non-maximum suppression At q,we have a maximum if the value is larger than those at both p and at r. Interpolate to get these values.
  • 31.
    Assume the markedpoint is an edge point. Then we construct the tangent to the edge curve (which is normal to the gradient at that point) and use this to predict the next points (here either r or s). Edge linking
  • 32.
    Discontinuity: Edge Linking1 Edge Linking: becomes an important approach after edge detection How to link edges? 1. First define a small window (3x3) or (5x5) 2. The center of this window is a pixel defined as an edge (x0 ,y0 ) 3. Check other pixels inside the window if considered as edges or not by calculating the gradient at each 4. A pixel (x,y) is considered linked edge if: 1. |G(x,y)-G(x0 ,y0 )| < E 2. Θ(x,y) - Θ(x0 ,y0 ) < A Where G is the magnitude of the gradient and Θ is the angle of the gradient E and A are magnitude and phase thresholds respectively
  • 33.
    Effect of (Gaussian kernel spread/size) Canny with Canny with original The choice of  depends on desired behavior • large  detects large scale edges • small  detects fine features
  • 34.
    Edge detection isjust the beginning… image human segmentation gradient magnitude
  • 35.
    35 Basic EdgeDetection by Using First-Order Derivative 2 2 1 ( ) The magnitude of ( , ) mag( ) The direction of ( , ) tan The direction of the edge -90 x y x y x y f g x f grad f f g y f M x y f g g f g x y g                                              
  • 36.
    36 Basic EdgeDetection by Using First-Order Derivative Edge normal: ( ) Edge unit normal: / mag( ) x y f g x f grad f f g y f f                             In practice,sometimes the magnitude is approximated by mag( )= + or mag( )=max | |,| | f f f f f f x y x y                
  • 37.
  • 38.
  • 39.
  • 40.
    40 Advanced Techniques forEdge Detection The Marr-Hildreth edge detector 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 4 2 4 2 2 ( , ) , :space constant. Laplacian of Gaussian (LoG) ( , ) ( , ) ( , ) 1 1 x y x y x y x y x y G x y e G x y G x y G x y x y x y e e x y x y e e x                                                                        2 2 2 2 2 2 4 x y y e             
  • 41.
  • 42.
    42 Marr-Hildreth Algorithm 1.Filter the input image with an nxn Gaussian lowpass filter. N is the smallest odd integer greater than or equal to 6 2. Compute the Laplacian of the image resulting from step1 3. Find the zero crossing of the image from step 2   2 ( , ) ( , ) ( , ) g x y G x y f x y   
  • 43.
    Edge Linking UsingHough Transform Effective method to solve linear segmentation problems Assume the following segmentation problem: A set of ‘n’ points are in a plane, We want to determine the points that are linked together to form a straight line Solution1: We will take a pair of points and form a straight line Check the number of remaining points that are close to this line This process is repeated for all possible pairs of points and each time the rest of points are checked for being part of this proposed line The line that has maximum number of points closer to it is the fittest one
  • 44.
    Edge Linking UsingHough Transform What is the problem concerned with solution 1 ? Large number of computations For ‘n’ points, we have nC2 = n 2 = n(n+1) 2 possible pairs to form the proposed lines Each case, we have to compare (n-2) points, if the proposed line passes closer to them or not The number of computations is then: n(n+1)(n+2) 2 Large mathematical computations
  • 45.
    Edge Linking UsingHough Transform  Solution by means of Hough Method, Hough proposed the following model:  Given that the equation of a straight line is: 𝒚 = 𝒂𝒙 + 𝒃 , “a” and “b” are the line parameters  At any point (x1 ,y1), we can write the equation of all lines passing through it as: 𝑦1 = 𝑎𝑥1 + 𝑏 𝒐𝒓 𝑏 = −𝑎𝑥1 + 𝑦1  We have got a linear equation between ‘a’ and ‘b’ that could be represented in another plane called: “The Parameter Space”  Thus each point (x,y) will be transformed into a straight line in the parameter space  If two lines in the parameter space -representing the pair of points (x1 ,y1 ) and (x2 ,y2 ) -will intersect at values (a, b)  These values’ couple ‘a’ and ‘b’ are parameters of the straight line joining them in original space  When all ‘n’ points are transformed into the parameter space domain, we will simply observe the values of (a,b) where the most points’ cloud density occurs.  These values for ‘a’ and ‘b’ are the required ones; and these points are linked to form the required line
  • 46.
  • 47.
    Hough Transform All linespassing in this crowded area are then inversely transformed to obtain the original points passing via the linked line with parameters (a,b)