1. CSE4227 Digital Image Processing
Chapter 10 – Image Segmentation (Part I)
CSE | AUST Spring 2024
Dr. Kazi A Kalpoma
Professor, Department of CSE
Ahsanullah University of Science & Technology (AUST)
Contact: kalpoma@aust.edu
Google Class code: fmxdafw
2. 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) ]
5. 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.)
6. 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).
7. 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
8. 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.
10. Detection of Isolated Points
❑ Point detection can be achieved simply using the
Laplacian mask.
Points are detected at those pixels in the subsequent filtered image
that are above a set threshold
-1 -1 -1
-1 8 -1
-1 -1 -1
11. Isolated Point Detection (example)
X-ray image of
a turbine blade
Result of point
detection
Result of
thresholding
12. Line Detection
❑ The masks below will extract lines that are one pixel
thick and running in a particular direction
❑ Note: preferred direction of each mask is weighted
with a larger coefficient (i.e.,2) than other possible
directions.
R1 R2 R3 R4
14. Line Detection
CSC447: Digital Image
Processing
Prof. Dr. Mostafa
GadalHaqq.
1
4
❑ 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.
15. Line Detection
CSC447: Digital Image
Processing
Prof. Dr. Mostafa
GadalHaqq.
1
5
❑ 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.
20. 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
21. 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.
22. 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.
24. 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.
26. 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.
27. ❖ The direction of an edge θ is orthogonal to the
direction of a gradient vector α
Gradient based Edge Detection
35. 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
36. Laplacian of Gaussian – LOG
We usually smooth the image applying Gaussian
filter prior to Laplacian filter.
46. ❑ 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
(step 2: finding gradient operator)
Canny Edge Detection Algorithm
49. ▪ 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)……
50. 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)……
54. ❑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.
(step 4: Hysteresis Thresholding)
Canny Edge Detection Algorithm
55. The ratio of the high and low threshold should be
two or three to one.
(step 4: Hysteresis Thresholding)…
Canny Edge Detection Algorithm
➔ Using two thresholds, a low threshold and a high
threshold.
56. ❑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.
(step 4: Hysteresis Thresholding)…
Canny Edge Detection Algorithm
57. ❑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.
(step 5: connectivity analysis)
Canny Edge Detection Algorithm
58. ❖ 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.
Example
63. 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