0% found this document useful (0 votes)
4 views

08_Lecture -Chapter 10- Image Segmentation_Part I_Edge Detection

Chapter 10 of the document focuses on Image Segmentation, detailing its definition, goals, applications, and various segmentation algorithms. It covers the detection of discontinuities, edge detection concepts, and specifically the Canny Edge Detection Algorithm, which includes steps such as smoothing, gradient calculation, non-max suppression, hysteresis thresholding, and connectivity analysis. The chapter emphasizes the importance of partitioning images into meaningful regions for analysis and the challenges posed by noise in edge detection.

Uploaded by

Yousuf ali Safin
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

08_Lecture -Chapter 10- Image Segmentation_Part I_Edge Detection

Chapter 10 of the document focuses on Image Segmentation, detailing its definition, goals, applications, and various segmentation algorithms. It covers the detection of discontinuities, edge detection concepts, and specifically the Canny Edge Detection Algorithm, which includes steps such as smoothing, gradient calculation, non-max suppression, hysteresis thresholding, and connectivity analysis. The chapter emphasizes the importance of partitioning images into meaningful regions for analysis and the challenges posed by noise in edge detection.

Uploaded by

Yousuf ali Safin
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 64

CSE4227 Digital Image Processing

Chapter 10 – Image Segmentation (Part


I)

Dr. Kazi A Kalpoma


Professor, Department of CSE
Ahsanullah University of Science & Technology (AUST)

Contact: [email protected]
Google Class code: fmxdafw

CSE | AUST Spring 2024


Today’s Contents
❑Image Segmentation
• Definition
• Goal
• Application
❑Types of Segmentation Algorithms
❑Detection Of Discontinuities
• Points
• Lines
❑Concept of Edge Detection
❑Canny Edge Detection Algorithm

• Chapter 10 from R.C. Gonzalez and R.E. Woods, Digital Image Processing
(3rd Edition), Prentice Hall, 2008 [ Section 10.1, 10.2 (excluding 10.2.7) ]
What does Image Segmentation do?
❑ Divide the image into different regions.
❑ Separate objects from background and give them
individual ID numbers (labels).
❑ Purpose is to partition an image into meaningful regions
with respect to a particular application.
For example, it allows us to:
• Count the number of objects of a certain type.
• Measure geometric properties (e.g., area, perimeter) of
objects in the image.
• Study properties of an individual object (intensity,
texture, etc.)
Principle Approaches of
Segmentation
Segmentation Algorithms are based on one of the two
basic properties of intensity values:

❑ Similarity
⮚Partitioning an image into regions that are similar
according to a set of predefined criteria.
❑Discontinuity
⮚Partitioning an image based on sharp changes in
intensity (such as edges in an image).
Types of Segmentation Algorithms
❑Similarity
⮚Thresholding – based on pixel intensities
⮚Region based – grouping similar pixels
⮚Match based – comparison to a given template

❑Discontinuity
⮚Edge based – detection of edges that separate regions
from each other
⮚Watershed – find regions corresponding to local minima
in intensity
Detection Of Discontinuities

❑ There are three basic types of gray-level


discontinuities:
* points * lines * edges

❑ We are interested in the behavior of the


derivatives in these discontinuities.

❑ The common way of achieving this


detection is to run a mask through the
image.
w1 w2 w3
w4 w5 w6
w7 w8 w9
Detection of Isolated Points

❑ Point detection can be achieved simply using the


Laplacian mask.
-1 -1 -1

-1 8 -1

-1 -1 -1

Points are detected at those pixels in the subsequent filtered image


that are above a set threshold
Isolated Point Detection (example)

X-ray image of Result of point Result of


a turbine blade detection thresholding
Line Detection
❑ The masks below will extract lines that are one pixel thick
and running in a particular direction

R1 R2 R3 R4

❑ Note: preferred direction of each mask is weighted with a


larger coefficient (i.e.,2) than other possible directions.
Line Detection
❑ Apply every masks on the image
❑ let R1, R2, R3, R4 denotes the response of
the horizontal, +45 degree, vertical and -45
degree masks, respectively.
❑ if, at a certain point in the image
|Ri| > |Rj|, for all j≠i,
❑ that point is said to be more likely
associated with a line in the direction of
mask i.
CSC447: Digital Image Prof. Dr. Mostafa 1
Processing GadalHaqq. 4
Line Detection
❑ Alternatively, if we are interested in detecting all
lines in an image in the direction defined by a
given mask, we simply run the mask through the
image and threshold the absolute value of the
result.
❑ The points that are left are the strongest
responses, which, for lines one pixel thick,
correspond closest to the direction defined by
the mask.

CSC447: Digital Image Prof. Dr. Mostafa 1


Processing GadalHaqq. 5
Edges

❑Edge is the boundary between


two homogeneous regions.
Edge Detection

Edge Detection - Identifying sudden


change in image intensity.
Edge Types
Edges & Derivatives

5 5 4 3 2 1 0 0 0 6 0 0 0 0 1 3 1 0 0 0 0 7 7 7 7

1st Derivative -1 -1 -1 -1 -1 0 0 6 -6 0 0 0 1 2 -2 -1 0 0 0 7 0 0 0

2nd Derivative -1 0 0 0 0 1 0 6 -12 6 0 0 1 1 -4 1 1 0 0 7 -7 0 0


Edges & Derivatives
❑Derivatives are used to
find discontinuities

❑1st derivative tells us


where an edge is

❑2nd derivative can


be used to show
edge direction too

Zero crossing
Characteristics of First and Second
Order Derivatives

Example Signal 1st Derivative of Signal 2nd Derivative of Signal

▪ 1ST DERIVATIVE SHOWS A MAXIMUM AT THE CENTER OF THE EDGE SIGNAL.

▪ 2ND DERIVATIVE PASSES THROUGH ZERO (CHANGES ITS SIGN) AT THE


CENTER OF THE EDGE SIGNAL.
Zero-crossing Feature

❖ A zero crossing is a point where the sign of a


mathematical function changes in the graph of the
function.
❖ In image processing, the edge detection using
Laplacian filter takes place by marking the points
that leads to zero in graph as potential edge points.
❖ This method works fine on images for finding edges
in both directions, but it works poorly when noises
are found in the image.
Derivatives & Noise
❑Derivative based edge detectors are extremely
sensitive to noise
❑We need to keep this in mind
Methods of Edge Detection
❑ The majority of different edge detection methods may be
grouped into two categories:

⮚ Gradient based Edge Detection:


The gradient method detects the edges by looking for the
maximum and minimum in the first derivative of the image.

⮚ Laplacian based Edge Detection:


The Laplacian method searches for zero crossings in the
second derivative of the image to find edges. An edge has the
one-dimensional shape of a ramp and calculating the derivative
of the image can highlight its location.
Edge Detection Algorithms
Three main steps in Edge Detection

1. Filtering (Smoothing)
In this stage image is pass through a filter to remove
the noise.
2. Differentiation (Edge sharpening using derivatives)
this stage highlights the location in the image where
intensity changes i.e. detects discontinuities.
3. Detection (Thresholding)
this stage take decision on the edge pixel i.e. where
the changes are significant.
4. Localization
determine the exact location of an edge.
Gradient based Edge Detection

❖ The direction of an edge θ is orthogonal to the


direction of a gradient vector α
Gradient – Prewitt Operator

-1 0 1 -1 -1 -1
-1 0 1 0 0 0
-1 0 1 1 1 1
Gradient – Sobel Operator

-1 0 1 -1 -2 -1
-2 0 2 0 0 0
-1 0 1 1 2 1
Basic Edge Detection by Sobel

-1 0 1
-2 0 2
-1 0 1

-1 -2 -1
0 0 0
1 2 1
Gradient based Edge Detection
cont.
Edge Detection Example
Original Image Horizontal Gradient Component

Vertical Gradient Component Combined Edge Image


Edge Detection Problems
Edge Detection Problems

❑Often, problems arise in edge detection in that


there are too much details

❑For example, the brickwork in the previous


example

❑One way to overcome this is to smooth images


prior to edge detection
Laplacian of Gaussian – LOG

We usually smooth the image applying Gaussian


filter prior to Laplacian filter.
Laplacian Of Gaussian
Laplacian of Gaussian - LOG
Laplacian of Gaussian – LOG
(Marr Hildreth Algorithm)
Marr-Hildreth Algorithm
Canny Edge Detection
Canny Edge Detection Algorithm
Canny Edge Detection Algorithm
(step 1: smoothing/noise reduction)
Result after step 1

f(x,y) fs(x,y)
Canny Edge Detection Algorithm
(step 2: finding gradient operator)
❑ Compute the derivative of smoothed image fs(x,y)
❑ Calculate the Gradient Magnitude and Direction.
❑ Any of the filter mask pairs can be use to get the derivatives.

gy gx
Result after step 2

fs(x,y) M(x,y)
Canny Edge Detection Algorithm
(step 3: Non-Max Suppression)
(step 3: Non-Max Suppression)……
▪ Fro each pixel, the neighboring pixels are located in horizontal, vertical,
and diagonal directions (0°, 45°, 90°, and 135°).
▪ Thus we need to round off the gradient direction at every pixel to one of
these directions as shown below.
(step 3: Non-Max Suppression)……

Example:
▪ Suppose for a pixel ‘A’, the gradient direction comes out to be 17 degrees.
▪ Since 17 is nearer to 0, we will round it to 0 degrees.
▪ Then we select neighboring pixels in the rounded gradient direction (See
B and C in below figure).
▪ If the magnitude value M(x,y) of A is greater than that of B and C, it is
retained as an edge pixel otherwise suppressed.
(step 3: Non-Max Suppression)……
(step 3: Non-Max Suppression)……
Result after step 3

M(x,y) gN(x,y)
Canny Edge Detection Algorithm
(step 4: Hysteresis Thresholding)

❑Final operation is to threshold gN(x,y) to reduce false


edge points.
▪ Non-max suppression outputs a more accurate
representation of real edges in an image.
▪ But you can see that some edges are more bright than
others.
▪ The brighter ones can be considered as strong edges but
the lighter ones can actually be edges or they can be
because of noise.
▪ To solve the problem of “which edges are really edges and
which are not” Canny uses the Hysteresis Thresholding.
Canny Edge Detection Algorithm
(step 4: Hysteresis Thresholding)…

➔ Using two thresholds, a low threshold and a high


threshold.

The ratio of the high and low threshold should be


two or three to one.
Canny Edge Detection Algorithm
(step 4: Hysteresis Thresholding)…

❑In Hysteresis thresholding, we set two thresholds


‘High’ and ‘Low’.

❑If the threshold is set too low, there will still be


some false edge which is called false positive.
❑If the threshold is set too high, then actual valid
edge points will be eliminated which is called
false negative.
Canny Edge Detection Algorithm
(step 5: connectivity analysis)

❑Connectivity analysis to detect and link edges


❑For the edge pixels values of gNH(x,y) and gNL(x,y).
– Any edges with intensity greater than ‘High’ are the sure
edges.
– Any edges with intensity less than ‘Low’ are sure to be
non-edges.
– The edges between ‘High’ and ‘Low’ thresholds are
classified as edges only if they are connected to a sure
edge otherwise discarded.
Example

❖ Here, A and B are sure-edges as they are above ‘High’


threshold.
❖ Similarly, D is a sure non-edge.
❖ Both ‘E’ and ‘C’ are weak edges
❖ Since ‘C’ is connected to ‘B’ which is a sure edge, ‘C’ is
also considered as a strong edge.
❖ Using the same logic ‘E’ is discarded. This way we will get
only the strong edges in the image.
❖ This is based on the assumption that the edges are long
lines.
(step 5) cont…
Example
200 0 0
0 0 57

0 0 101
0 45 0

0 0 0
50 0 0

gnH(x,y) gnL(x,y)
200 0 57

0 45 101

0 0 0

g(x,y)
Final Result after step 5

gN(x,y) g(x,y)
Canny Edge Detection: Summary

• Smooth the input image with a Gaussian filter

• Compute the gradient magnitude and angle images

• Apply non maxima suppression to the gradient


magnitude image

• Use double thresholding and connectivity analysis to


detect and link edges
Edge detection in noisy images using different
differentiation

You might also like