0% found this document useful (0 votes)
15 views96 pages

Dip M5

The document provides an overview of image segmentation techniques, focusing on classification methods such as local and global segmentation, as well as region-based approaches. It discusses various algorithms including region growing, region splitting, and clustering techniques like hierarchical and partitional clustering. Key concepts include the importance of pixel connectivity, the role of thresholds, and edge detection in segmenting images for analysis in computer vision.

Uploaded by

projectvg15
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views96 pages

Dip M5

The document provides an overview of image segmentation techniques, focusing on classification methods such as local and global segmentation, as well as region-based approaches. It discusses various algorithms including region growing, region splitting, and clustering techniques like hierarchical and partitional clustering. Key concepts include the importance of pixel connectivity, the role of thresholds, and edge detection in segmenting images for analysis in computer vision.

Uploaded by

projectvg15
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 96

DIGITAL IMAGE PROCESSING

MODULE 5
S . I N
IMAGE
TUN OS
T E
EGMENTATION
K
References:
• S. Jayaraman, S. Esakkirajan, “DIGITAL IMAGE PROCESSING”
• Rafael C Gonzalez, R Woods, “DIGITAL IMAGE PROCESSING”

Downloaded from Ktunotes.in


Syllabus
• Classification of Image Segmentation techniques
• Region Approach
– Clustering Techniques

E S . I N
• Segmentation based on Thresholding
O T
• Edge based K TUN
Segmentation
– Classification of Edges
– Edge Detection
• Hough transform
• Active Contour

Downloaded from Ktunotes.in


Image Segmentation
• Image segmentation divides an image into
regions that are connected and have some
similarity within the region and some
difference between adjacent . I regions.
N
• The goal is usually O T E S
K T U N to find individual objects
in an image.
• Segmentation is concerned with dividing an
image into meaningful regions.
Image segmentation is a crucial task in computer vision that involves dividing an image
into multiple segments or regions, often to simplify the representation of an image or make
it more meaningful and easier to analyze. The goal of image segmentation is to assign a
label to every pixel in an image such that pixels with the same label share certain
characteristics.
Downloaded from Ktunotes.in
Classification of Image Segmentation Techniques
• Local Segmentation
– Segmenting sub-images which are small windows on a
whole image
– Number of pixels available will be lower than the global
segmentation
S . I N
T U N OTE
– Must be frugal in its demand for pixel data
• K
Global Segmentation
– Concerned with segmenting a whole image
– Global segmentation deals with segments consisting of a
relatively large number of pixels
– This makes estimated parameter values for global
segments more robust

Downloaded from Ktunotes.in


Approaches to segmentation
• 2 kinds of approaches to segmentation
– discontinuity
– similarity

S . I N
T U N OTE
K

Downloaded from Ktunotes.in


Feature Global Segmentation Local Segmentation
Scope Entire image Local regions or small parts
Criteria Single, uniform Multiple, adaptive
Complexity Simpler More complex
Sensitivity Sensitive to global variations Robust to local variations

S . I N
OTE
Application Suitable for images with uniform properties Suitable for images with varying properties

(LBP)
K T U N
Examples Global thresholding, K-means clustering
, Fourier Transform-based segmentation
Adaptive thresholding,
region growing, Local Binary Patterns

Downloaded from Ktunotes.in


Image segmentation approaches

S . I N
• Region approachT U N OTE
K
– Each pixel is assigned to a particular object or region.
• Boundary approach
– Attempt is to locate directly the boundaries that exist
between the regions
• Edge approach
– Edges are identified first, and are linked together to form
required boundaries
Downloaded from Ktunotes.in
Region Approach to Image Segmentation
• Regions in an image are a group of connected pixels
with similar properties.
• In region approach, each pixel is assigned to a
particular object or region.
• Region-based segmentation is based on the connectivity
S . I N
T U N OTE
of similar pixels in a region.
K
• Each region must be uniform.
• Connectivity of the pixels within the region is very important.
• 3 main approaches to region-based segmentation:
– Region growing
– Region splitting
– Region splitting and merging

Downloaded from Ktunotes.in


Region-Based Segmentation - Basic Formulation

• Let R represent the entire image region.


• Segmentation is a process that partitions R into
subregions, R1,R2,…,Rn, such that
n

(a )  Ri  R
i 1
E S . I N
U N O
(b)R i is a connected region, Ti= 1,2,...,n
(c) R ∩ R = φ K
i forTall i and j ,i≠ j
j
(d) P (R i )= TRUE for i= 1,2,...,n
(e) P( R i∪ R j )= FALSE for any adjacent regions Ri and R j
where P(Rk): a logical predicate defined over the points in
set Rk
For example: P(Rk)=TRUE if all pixels in Rk have the same
gray level. Downloaded from Ktunotes.in
Region Growing
• Groups pixels or sub-regions into larger regions based on predefined
criteria.
• Neighbouring pixels are examined and added to a region class if no edges
are found.
• This process is iterated for each boundary pixel in the region.
• The basic idea is to start with a set of seed points and from these grow
regions by appending to each seed those neighboring pixels that have
S . I N
properties similar to the seed (specified ranges of gray level or colour)
N OTE
• Seed points are found out by computing the same set of properties for
T U
K
every pixel values.
• The resultant segment is removed from the process
• New seed is chosen from the remaining pixels.
• This continues until all pixels have been allocated to a segment
• Region-growing algorithms vary depending on the criteria used to decide
whether a pixel should be included in the region or not, the connectivity
type used to determine neighbours and the strategy to visit neighbouring
pixels
Downloaded from Ktunotes.in
Region growing is a
simple and effective
image segmentation
technique that starts
from one or more seed
points and iteratively
adds neighboring pixels
that have similar
properties to the growing
region. This method is
particularly useful for

S . I N segmenting images with

T U N OTE well-defined regions and


distinct boundaries.
K

Downloaded from Ktunotes.in


Region-Based Segmentation
Region Growing

S . I N
T U N OTE
K

Downloaded from Ktunotes.in


Region Splitting

• Region splitting is the opposite of region


growing.
• First there is a large region (possible the entire
image).
S . I N
OTE
• Then a predicate (measurement) is used to
T U N
determine if the region is uniform.
K
• If not, then the method requires that the region be
split into two regions.
• Then each of these two regions is independently
tested by the predicate (measurement).
• This procedure continues until all resulting regions
are uniform.
Downloaded from Ktunotes.in
Region Splitting and Merging

• The main problem with region splitting is determining


where to split a region.
• One method to divide a region is to use a quadtree
structure.
• Quadtree: a tree in which nodes have exactly four
descendants.
S . I N
T U N OTE
K

Downloaded from Ktunotes.in


• Splitting
– Let R be the Entire image
– Split or subdivide image successively such that the
segregated parts are more homogeneous than the whole
– The final partition is likely to contain adjacent regions
with identical properties
• Merge
– Merge any adjacent regions that are similar enough
S . I N
T U N OTE
• K Algorithm
Split and Merge
– Start with the whole image
– If the variance is too large, break it into quadrants
– Merge adjacent regions that are similar enough
– Repeat step 2 and 3 iteratively until no more splitting
or merging occurs
Downloaded from Ktunotes.in
S . I N
T U N OTE
K

Downloaded from Ktunotes.in


S . I N
T U N OTE
K

Downloaded from Ktunotes.in


S . I N
T U N OTE
K

Downloaded from Ktunotes.in


S . I N
T U N OTE
K

Downloaded from Ktunotes.in


S . I N
T U N OTE
K

Downloaded from Ktunotes.in


S . I N
T U N OTE
K

Downloaded from Ktunotes.in


Clustering Techniques
• Refers to the classification of objects into groups
according to certain properties of these objects.
• Patterns within a cluster are more similar to each
other than patterns belonging to different clusters.
• An attempt is made to extractSa.Ifeature
E N vector from
local areas in theU N O
image. T
K T
• Clustering- to assign each pixel to the class of the
nearest cluster mean. Clustering techniques in image segmentation
involve grouping pixels based on their similarity
• Clustering in feature space, such as color, intensity, or
texture. These methods partition an image into
– Hierarchical clusters where pixels in the same cluster share
similar characteristics
– Partitional

Downloaded from Ktunotes.in


Hierarchical Clustering
• Hierarchical clustering techniques are based on the use of a proximity
matrix indicating the similarity between every pair of data points to be
clustered.
• Build a tree-based hierarchical taxonomy (dendrogram) from a set of
documents.
• The end result is a tree of clusters representing the nested group of
patterns and similarity levels at which groupings change.
• The resulting clusters are always produced as the internal nodes of the
S . I N
OTE
tree.
T U N
• Root node is reserved for the entire dataset
K
• leaf nodes are for individual data samples

• Clustering is obtained by
cutting the dendrogram at a
desired level: each connected
component forms a cluster.

Downloaded from Ktunotes.in


Hierarchical Clustering algorithms

• Agglomerative (bottom-up):
– Start with each document being a single cluster.
– Merge clusters to be larger and larger by starting with N
single point clusters
– Eventually all documents belong to the same cluster.
S . I N
• Divisive (top-down): N
T U OTE
K
– Start with all documents belong to the same cluster.
– Iterative splitting of the dataset until the single-point
clusters are attained on leaf nodes
– Eventually each node forms a cluster on its own.
– Does not require the number of clusters k in advance

Downloaded from Ktunotes.in


Hierarchical Agglomerative Clustering (HAC) Algorithm

• Start with all instances in their own cluster.


• Until there is only one cluster:
• Among the current clusters, determine the two
E S N
clusters, ci and cj, that are most.Isimilar.
• Replace ci and cU j N
withO a T
single cluster ci  cj
K T
• Algorithm can be divided into Hierarchical clustering is a
technique that builds a tree
− Single-link Algorithm (dendrogram) of clusters. It can
be either agglomerative
− Complete-link Algorithm (bottom-up) or divisive
− Minimum-variance Algorithm (top-down). In the context of
image segmentation,
hierarchical clustering can be
used to group pixels into
clusters based on their similarity.

Downloaded from Ktunotes.in


Single-link algorithm
• Merges 2 clusters according to the minimum distance
between the data samples from two clusters
• Algorithm allows for a tendency to produce clusters with
elongated shapes
• Use maximum similarity of pairs:
E S . I N
N O
sim ( c , c )  max Tsim (x, y)
KTU
i j
x c i , y c j

• Can result in “straggly” (long and thin) clusters due to


chaining effect.
• After merging ci and cj, the similarity of the resulting cluster
to another cluster, ck, is:
sim (( c i  c j ), c k )  max( sim ( c i , c k ), sim ( c j , c k ))

Downloaded from Ktunotes.in


Types of Hierarchical Clustering
Agglomerative Hierarchical
Single Link Example Clustering (Bottom-Up)

Starts with each pixel as an


individual cluster.
Iteratively merges the closest
pairs of clusters until all pixels are
in a single cluster or a stopping
criterion is met.
Divisive Hierarchical Clustering
(Top-Down)

E S . I N
OT
Starts with all pixels in a single

K T U N cluster.
Recursively splits clusters until
each pixel is its own cluster or a
stopping criterion is met.

Downloaded from Ktunotes.in


Complete Link Agglomerative Clustering

• Complete-link algorithm incorporates the maximum


distance between data samples in clusters
• Use minimum similarity of pairs:
sim ( c i , c j )  S . I N
OTE
min sim ( x , y )

K T U Nx c i , y c j

• Makes “tighter,” spherical clusters that are typically


preferable.
• After merging ci and cj, the similarity of the resulting
cluster to another cluster, ck, is:

sim (( c i  c j ), c k )  min( sim ( c i , c k ), sim ( c j , c k ))

Downloaded from Ktunotes.in


Complete Link Example
Advantages of Hierarchical
Clustering:
No Need for Number of Clusters:
Unlike K-Means, it does not
require the number of clusters to
be specified initially.
Hierarchical Structure: Provides
a hierarchy of clusters which can

S . I N be useful for understanding the

OTE
data structure.

K T U N Flexibility: Can handle various


shapes and sizes of clusters.

Downloaded from Ktunotes.in


Minimum – Variance Algorithm

• Combines 2 clusters in the sense of


minimising the cost function.
• ie. With minimum variance between the
S . I N
clusters OTE T U N
K
Disadvantages of Hierarchical Clustering:
Computational Complexity: Can be computationally expensive, especially for large datasets.
Memory Usage: Requires storing the distance matrix, which can be memory-intensive.
Sensitivity to Noise and Outliers: Can produce poor results if the data contains noise or outliers.

Applications:
Hierarchical clustering is widely used in various fields, including:

Bioinformatics: Clustering genes or proteins based on their expression levels or sequence similarity.
Marketing: Segmenting customers based on purchasing behavior or demographic data.
Document Clustering: Grouping similar documents for information retrieval or topic modeling.

Downloaded from Ktunotes.in


Partitional Clustering
• Uses an iterative optimisation procedure that aims at
minimising an objective function f. Partitional clustering methods divide the
image into non-overlapping clusters

• f measures the goodness of clustering Unlike hierarchical clustering, partitional


directly by optimizing a certain criterion.

methods provide a single partition of the


• Composed of 2 learning steps data instead of a hierarchy. The most
common partitional clustering algorithm is
K-Means, but other methods like
– Partitioning of each pattern to its closest cluster
K-Medoids and Fuzzy C-Means are also

– Computation of the cluster centroidsS . I N widely used.

U N OTE
• Procedure start from an initial solution with a known
T
number of clusters
K
• Categorised into
– Partitioning relocation algorithms
 Probabilistic clustering
 K-medoids
 K-means Clustering
– Density-based partitioning
Downloaded from Ktunotes.in
K-Means clustering is a popular
partitional clustering algorithm used
in image segmentation and various

Clustering via K-Means Algorithm other tasks. It aims to partition a


dataset into K clusters, where each
data point belongs to the cluster
with the nearest mean (centroid).

• It is an iterative procedure
• Clusters data by iteratively computing a mean intensity
for each class and segmenting the image by classifying
each pixel in the class with the closest mean.
S . I N
T U N OTE
K
Initialization: randomly the data points are the centroid is
choose assigned to the K updated for each
K centroids sets set

Downloaded from Ktunotes.in


Procedure in K-means clustering
• Choose 𝑘 initial cluster centroids 𝑧1 𝑙 , 𝑧2 𝑙 , . . . , 𝑧𝑘 𝑙
• At the 𝑘 𝑡ℎ iterative step, distribute the samples 𝑥 among the 𝐾
clusters using the relation
𝒙 ∈ 𝑪𝒋 𝒌 𝒊𝒇 𝒙 − 𝒛𝒋 𝒌 < 𝒙 − 𝒛𝒊 𝒌
For 𝑖 = 1,2, … , 𝐾, 𝑖 ≠ 𝑗, where 𝐶𝑗 𝑘 denotes the set of samples
whose cluster centre is 𝑧𝑗 𝑘
S . I N
• Compute the new cluster centres𝑧𝑗 𝑘 + 1 , j = 1,2, … , 𝐾, such
N OTE
that the sum of the squared distance from all points in 𝐶𝑗 𝑘 to
T U
K
the new cluster is minimised. The measure which minimises this is
simply the sample mean of 𝐶𝑗 𝑘 . New cluster is given
1
by 𝑧𝑗 𝑘 + 1 = 𝑥∈𝐶𝑗 𝑘 𝑥
𝑁𝑗
• If 𝑧𝑗 𝑘 + 1 is unchanged, the algorithm has converged and the
procedure is terminated. Otherwise go to step 2.

• Drawback of K-means algorithm is that the number of clusters is


fixed, once K is chosen and it always returns K cluster centres
Downloaded from Ktunotes.in
K-means Clustering: Step 1
Algorithm: k-means, Distance Metric: Euclidean Distance
5

4
k1

3
S . I N
UkN OTE
2 KT 2

k3
0
0 1 2 3 4 5

Downloaded from Ktunotes.in


K-means Clustering: Step 2
Algorithm: k-means, Distance Metric: Euclidean Distance
5

4
k1

3
S . I N
UkN OTE
2 KT 2

k3
0
0 1 2 3 4 5

Downloaded from Ktunotes.in


K-means Clustering: Step 3
Algorithm: k-means, Distance Metric: Euclidean Distance
5

4
k1

3
S . I N
T U N OTE
2 K
k3
1
k2

0
0 1 2 3 4 5

Downloaded from Ktunotes.in


K-means Clustering: Step 4
Algorithm: k-means, Distance Metric: Euclidean Distance
5

4
k1

3
S . I N
T U N OTE
2 K
k3
1
k2

0
0 1 2 3 4 5

Downloaded from Ktunotes.in


K-means Clustering: Step 5
Algorithm: k-means, Distance Metric: Euclidean Distance

expression in condition 2 5

4
k1

3
S . I N
T U N OTE
2 K
k2
k3
1

0
0 1 2 3 4 5

expression in condition 1
Downloaded from Ktunotes.in
Fuzzy Clustering
• Clustering methods can be classified as HARD or FUZZY
• In hard clustering, data is divided into distinct clusters,
where each data element belongs to exactly one cluster.
In fuzzy clustering (also referred to as soft clustering), data
elements can belong to more than one cluster, and
. I N
associated with each element is a set of membership levels.
S
N OTE
• These indicate the strength of the association between that
T U
K
data element and a particular cluster. Fuzzy clustering is a
process of assigning these membership levels, and then
using them to assign data elements to one or more clusters.
• Fuzzy clustering methods can be considered to be superior
to those of their hard counterparts since they can represent
the relationship between the i/p pattern data and clusters
more naturally.
Downloaded from Ktunotes.in
Fuzzy Clustering

S . I N
T U N OTE
K

Downloaded from Ktunotes.in


Image Segmentation based on Thresholding

• Thresholding techniques produce segments having pixels


with similar intensities
• Useful for establishing boundaries in images that contain
solid objects resting on a contrasting background
S . I
• Thresholding requires that an object has homogeneous N
T U N OTE
intensity and a background with a different intensity level
K
Image thresholding involves dividing an image into two or more regions
• Types based on intensity levels, allowing for easy analysis and extraction of
desired features. By setting a threshold value, pixels with intensities above
– Global Thresholding or below the threshold can be classified accordingly This technique aids in
tasks such as object detection, segmentation, and image enhancement.
– Local Thresholding (For a small part of the image, Thresholding is used)
Image thresholding is a technique that simplifies a
– Adaptive Thresholding grayscale image into a binary image by classifying each
pixel value as either black or white based on its intensity
– Histogram-based Thresholding level or gray-level compared to the threshold value. This
technique reduces the image to only two levels of intensity,
making it easier to identify and isolate objects of interest.
Binary image conversion allows for efficient processing and
analysis of images, enabling various computer vision
applications such as edge detection and pattern recognition.
Downloaded from Ktunotes.in
Global Thresholding
• A threshold value T is chosen as the threshold.
1 𝑖𝑓 𝑓(𝑚, 𝑛) ≥ 𝑇
𝑓 𝑚, 𝑛 =
0 𝑒𝑙𝑠𝑒
• Value of T has to be selected in an optimal manner

S . I N
T U N OTE
K

Downloaded from Ktunotes.in


Selection of Threshold T inGlobal
Global Thresholding
Thresholding is a widely used technique where a single
threshold value is applied to an entire image. However, this
technique may not be suitable for images with varying lighting
Basic Global Thresholding: conditions or complex backgrounds.

1. Select an initial estimate for T.


2. Segment the image using T. This will produce two groups of
pixels: G1 consists of all pixels with gray level values > T and
G2 consists of pixels with values <= T.
S . I N
3. Compute the average gray level values µ1 and µ2 for the
U N
pixels in regions G1 and G2.
T OTE
K
4. Compute a new threshold value: T = ½ (µ1 + µ2 ).
5. Repeat steps 2 through 4 until the difference in T in
successive iterations is smaller than a predefined parameter
To overcome this limitation, adaptive
T0. thresholding techniques may be
employed, which adjust the threshold
• Error will be more in Global Thresholding.value locally based on the
characteristics of each pixel's
neighborhood. These techniques are
• So Adaptive Thresholding is used. particularly useful in scenarios where
there is significant variation in
illumination across different regions of
Downloaded from Ktunotes.in the image.
Adaptive Thresholding has advantages over global
thresholding. One advantage is that it can handle images

Adaptive Thresholding with varying lighting conditions or uneven illumination.


This is because adaptive thresholding calculates the
threshold value locally, taking into account the specific
characteristics of each sub-region.

• In many cases, background gray level is not a constant


• Object contrast varies within an image
• So, threshold in one area might not work well in other
areas of the image. Additionally, adaptive
thresholding can help
preserve important details
• So, global thresholding can’t be used there.
• Adaptive ThresholdingOTE S . I N and fine textures in an
image, as it adjusts the
threshold value based on

T U N
K into sub-images.
 Divide the image
the local pixel intensities.

 Assume that the illumination in each sub-images is


constant.
applications  Use a different threshold for each sub-image.
 Alternatively – use a running window (and use the
threshold of the window only for the central pixel )
Noise Reduction: Thresholding can be utilized for noise reduction, as it can help to eliminate unwanted artifacts or
disturbances in an image.
Edge Detection: Image thresholding aids in identifying and highlighting the boundaries between different objects or regions
within an image with edge detection algorithms.
Downloaded from Ktunotes.in
Object Detection: By setting a threshold value, objects can be separated from the background, allowing for more accurate
and efficient object detection.

Comparison of Global and adaptive thresholding


Medical Images: Image thresholding can be used to segment different structures or abnormalities for diagnosis and
analysis in medical imaging.
Quality Control: Image thresholding plays a crucial role in quality control processes, such as inspecting manufactured
products for defects or ensuring consistency in color and texture of a color image.

S . I N
T U N OTE
K
Object Segmentation:
Image thresholding is
also commonly used in
computer vision tasks
such as object
segmentation, where it
helps to separate
foreground objects from
the background. This
enables more accurate
and efficient detection
of objects within an
image.

Downloaded from Ktunotes.in


Histogram based Threshold selection

S . I N
T U N OTE
K
• If two dominant modes characterize the image histogram, it
is called a bimodal histogram. Only one threshold is enough
for partitioning the image.
• If for example an image is composed of two types of light
objects on a dark background, three or more dominant
modes characterize the image histogram.
Downloaded from Ktunotes.in
Histogram based Threshold selection

• 2 peaks correspond to the relatively large number


of points inside and outside the object
• Dip between the peaks corresponds to the relatively
few points around the edge of the
E S . I Nobject
• Dip is usually used
U N
to O T
establish the threshold gray
K T
level
• If noise is present in the image, histogram will also
be noisy.
• In those cases, histogram can be smoothened first.

Downloaded from Ktunotes.in


Limitation of Thresholding Technique
• In its simplest form, only 2 classes are generated
and it cannot be applied to all types of images
• Thresholding technique doesn’t take into account

E S I N
the spatial characteristics of an.image.
• This causes it to U
be N O T
sensitive to noise and intensity
K T
inhomogeneities.
• No guarantees of object coherency— may have
holes, extraneous pixels, etc.

Downloaded from Ktunotes.in


Edge-Based Segmentation
• Exploits spatial information by detecting the edges in an image.
• Edges -> Discontinuities in the homogeneity criterion for
segments.

S . I N
T U N OTE
K

Downloaded from Ktunotes.in


S . I N
T U N OTE
K

Downloaded from Ktunotes.in


Edge Detection
• Process of finding meaningful transitions in an image.
• The points where sharp changes in the brightness occur
typically form the border between different objects.
• These points can be detected by computing intensity
differences in local image regions.
. I N
• Edge-detection algorithm should look for a neighbourhood
S
U N OTE
with strong signs of change
T
K
• Most of the edge detectors work on measuring the intensity
gradient at a point in the image
• In images, edges characterize object boundaries and are
useful for segmentation and identification of objects in a
scene

Downloaded from Ktunotes.in


Derivatives to find Edges

S . I N
T U N OTE
K

Downloaded from Ktunotes.in


Edge detection Methods (Refer Text)
• Using
– Gradient Operator
– First order Derivatives
– Roberts Kernel
– Prewitt Kernel
– Sobel Kernel
E S . I N
– Frei-Chen EdgeU N O
DetectorT
– K T
Second Derivative Method
– Laplacian of Gaussian
– Difference of Gaussians Filter (DoG)
– Canny Edge Detector

Downloaded from Ktunotes.in


Edge detection using Gradient Operator

S . I N
T U N OTE
K

Downloaded from Ktunotes.in


Gradient Operator Example

S . I N
T U N OTE
K

Downloaded from Ktunotes.in


Gradient Operator Example

S . I N
T U N OTE
K

Downloaded from Ktunotes.in


Edge detection using First-order Derivatives
• First derivative must be
– Zero in flat segments (Constant gray-level values)
– Non-zero at the beginning of a gray level step or ramp
– Non-zero along ramp
• An image f(x,y) is a function in 2 variables.
N
T E S . I
UN O
• So, we will take partial derivatives.
KT

Downloaded from Ktunotes.in


First derivative for Edge Detection

S . I N
T U N OTE
K

Downloaded from Ktunotes.in


Roberts Kernel
• Main objective is to determine the differences b/w adjacent
pixels.
• Use {+1, -1} that calculates the difference b/w adjacent pixels
 Forward differences.
• Roberts kernels are too small to reliably find edges in the
presence of noise.
S . I N
N OTE
• Cross Gradient operator is given by
T U
K

• 2 x 2 mask is given by

Downloaded from Ktunotes.in


Prewitt Kernel
• Based on the idea of central difference.
• Better operator than Roberts operator.
• Consider the pixel arrangement

S . I N
T U N OTE
K
• Setting c = 1, Prewitt operator mask is given by

• Prewitt mask differentiates in one direction and averages in


other direction  So, edge detector is less vulnerable to noise
Downloaded from Ktunotes.in
Sobel Kernel
• Relies on central differences but gives greater
weight to the central pixels when averaging
• Sobel mask is given by

S . I N
T U N OTE
K
• Noise suppression characteristic is better
than prewitt mask

Downloaded from Ktunotes.in


Prewitt and Sobel kernel for diagonal edge detection

S . I N
T U N OTE
K

Edge detection using sobel mask


Downloaded from Ktunotes.in
Frei-Chen Edge detector
• Edge detection is implemented by mapping the intensity vector
using a linear transformation and then detecting edges based on
the angle b/w the intensity vector and its projection onto the edge
subspace.
• Normalized weights.
• A 3 x 3 image area is represented with the weighted sum of 9 Frie-
Chen masks.
• Image is primarily convolved with each of the 9 masks. Then an
S . I N
innerproduct of the convolution results of each mask is performed

T U N OTE
• 9 frie-chen masks are given below
K

Downloaded from Ktunotes.in


Second derivative method of Edge detection
• Finding the ideal edge is
equivalent to finding the point
where the derivative is max or
min.
• To find the point where derivative
is max, differentiate the derivative
S . I N
T U N OTE
 second derivative and equate
to zero. K
• Finding the optimal edge is
equivalent to finding places where
the second derivative is zero.
• Zero crossing is the place where
one pixel is positive and a
neighbouring pixel is negative.
Downloaded from Ktunotes.in
Laplacian operator
• The problems with zero crossing methods are
– Zero crossing methods produce 2-pixel thick edges
– Zero crossing methods are extremely sensitive to noise

• For images, there is a single


S . I N
measure that
N O T E
measures the
K T U
second derivative which is
obtained by taking the dot product of 𝛻 with
itself
• 𝛻. 𝛻 = 𝛻 2 is called laplacian operator

Downloaded from Ktunotes.in


S . I N
T U N OTE
K
• Laplacian operator mask is given by

Downloaded from Ktunotes.in


Laplacian Operator

• Laplacian operator subtracts the brightness values of


each neighbouring pixels from the central pixel.
• When discontinuity is present within the
neighbourhood in the form of a point, line or edge,
Laplacian is a non zero value.
• It may be either +ve or –ve depending
E S . I N on where the
U O T
central point lies withNrespect to the edge
K T
• Laplacian operator is rotationally invariant.
• Drawbacks of Laplacian Operator
– Useful directional information is not available by the use of a
Laplacian operator
– Laplacian, being an approximation of second derivative,
doubly enhances any noise in the image

Downloaded from Ktunotes.in


Laplacian of Gaussian (LoG)
• Prominent source of performance degradation of Laplacian operator is
noise in the input image.
• Noise effects can be minimised by smoothing the image prior to edge
detection
• LoG operator smooths the image through convolution with a Gaussian-
shaped kernel followed by applying Laplacian operator.
. I N
– Step 1 : Smoothing the input image 𝑓(𝑚, 𝑛) by convolving it with Gaussian
S
mask 𝑕 𝑚, 𝑛 to get g 𝑚, 𝑛 ;
T U N OTE 𝑔 𝑚, 𝑛 = 𝑐𝑜𝑛𝑣(𝑓 𝑚, 𝑛 , 𝑕 𝑚, 𝑛 )
K
– Step 2 : Laplacian operator is applied to the result
𝑔′ 𝑚, 𝑛 = 𝛻 2 𝑔 𝑚, 𝑛 = 𝛻 2 (𝑐𝑜𝑛𝑣 𝑓 𝑚, 𝑛 , 𝑕 𝑚, 𝑛 )
−(𝑚2 +𝑛2 )
• Gaussian Mask is given by 𝑕 𝑚, 𝑛 = 𝑒 2𝜎2

Downloaded from Ktunotes.in


Laplacian of Gaussian kernel

S . I N
T U N OTE
K

• Since LoG operator is a second-derivative operator, influence of noise is


considerable. It always generates closed contour, which is not realistic
Downloaded from Ktunotes.in
Difference of Gaussian Filter (DoG)

• DoG filter is obtained by taking the difference


of 2 Gaussian functions.
• 𝑕 𝑚, 𝑛 = 𝑕1 𝑚, 𝑛 − 𝑕2 (𝑚, 𝑛)
S . I N
T U N OTE
K

Downloaded from Ktunotes.in


Canny Edge Detector
• Laplacian edge detection method doesn’t
really determine the maximum of the
gradient magnitude.
• Canny edge detector defines edges as zero-
crossings of second E S . I N
derivatives in the
U N O T
T
direction ofKthe greatest first derivative.
• It is a multi-stage algorithm to detect a wide
range of edges in images.

Downloaded from Ktunotes.in


Steps involved in Canny edge detection

1. Apply Gaussian filter to smooth the image in order to


remove the noise
2. Find the intensity gradients of the image
3. Apply Non-maximum suppression to get rid of
spurious response to edge detection
. I N
O T E S
K T U N
4. Apply double threshold to determine potential edges
5. Track edge by hysteresis: Finalize the detection of
edges by suppressing all the other edges that are
weak and not connected to strong edges.

Downloaded from Ktunotes.in


Explanation
1. Gaussian filter
2. Intensity gradient:
– A 2D first derivative operator is applied to the smoothened image
to highlight regions of the image with high spatial derivatives.
Edges give rise to ridges in the gradient magnitude image.
3. Non-Maximal Suppression:
Non-Maximum suppression is applied to "thin" the edge.
After applying gradient calculation, the edge extracted from the
S . I N
OTE
gradient value is still quite blurred. There should only be one accurate

K T N
response to the edge. Thus non-maximum suppression can help to
U
suppress all the gradient values to 0 except the local maximal, which
indicates location with the sharpest change of intensity value. The
algorithm for each pixel in the gradient image is:
– Compare the edge strength of the current pixel with the edge
strength of the pixel in the positive and negative gradient directions.
– If the edge strength of the current pixel is the largest compared to
the other pixels in the mask with the same direction(i.e., the pixel
that is pointing in the y direction, it will be compared to the pixel
above and below it in the vertical axis), the value will be preserved.
Otherwise, the value will be suppressed.
Downloaded from Ktunotes.in
Applying double threshold (Hysteresis)
• There are still some edge pixels at this point caused by noise
and color variation. It is essential to filter out the edge pixel
with the weak gradient value and preserve the edge with the
high gradient value.
• Set two threshold values – High threshold value 𝑇1 and Low
threshold value 𝑇2
S . I N
N OTE
• If the edge pixel’s gradient value is higher than 𝑇1 , they are
T U
K
marked as strong edge pixels.
• If the edge pixel’s gradient value is smaller than 𝑇1 and larger
than 𝑇2 , they are marked as weak edge pixels.
• If the pixel value is smaller than 𝑇2 , they will be suppressed.
• The two threshold values are empirically determined values,
which will need to be defined when applying to different
images.
Downloaded from Ktunotes.in
Track edge by hysteresis

• The weak edge pixels can either be extracted from the true
edge, or the noise/color variations.
• the weak edge pixel caused from true edges will be
connected to the strong edge pixel.
• To track the edge connection, Binary Large OBject-analysis is
S . I N
T U
neighborhood pixels. OTE
applied by looking at a weak edge pixel and its 8-connected
N
K
• As long as there is one strong edge pixel is involved in the
BLOB, that weak edge point can be identified as one that
should be preserved.

Downloaded from Ktunotes.in


Canny Edge detector Example

S . I N
T U N OTE
K

Downloaded from Ktunotes.in


Roberts cross-gradient operators

S . I N
T U N OTE
Prewitt operators
K

Sobel operators

Downloaded from Ktunotes.in


Detection of Discontinuities
Gradient Operators

Prewitt masks for


detecting diagonal edges

S . I N
T U N OTE
K
Sobel masks for
detecting diagonal edges

Downloaded from Ktunotes.in


Comparison of different edge detection operators

S . I N
T U N OTE
K

Downloaded from Ktunotes.in


Edge Linking
• If the edges are relatively strong and the noise level is low,
one can threshold an edge-magnitude image and thin the
resulting binary image down to single pixel wide closed,
connected boundaries.
• Under less-than-ideal conditions, such an edge image will
have gaps that must be filled.
. I N
• Small gaps can be filled by searching a 5x5 or larger
S
U N OTE
neighbourhood, centered on as end point, for other end
T
K
points, and then filling in boundary pixels as required to
connect them.
• Two main categories of methods:
– (1) Local methods (extend edges by seeking the most "compatible"
candidate edge in a neighborhood). Local methods can not handle big gaps.
– (2) Global methods (more computationally expensive - domain knowledge
can be incorporated in their cost function)

Downloaded from Ktunotes.in


Local processing methods
• (1) At each edge pixel, a neighborhood (e.g., 3x3) is
examined.
• (2) The center edge pixel can be linked with its
neighbors if the magnitude and direction differences of
the gradient vectors are below certain thresholds and
S . I N
OTE large:
their magnitudes are relatively
T U N
K
 f(x, y)   (x 0 , y 0 )  E, E : a nonnegativ e threshold

α(x, y)  α(x 0 , y 0 ) < A, A : a nonegative angle threshold

Downloaded from Ktunotes.in


Edge linking through Heuristic search (Local)
• A quality measure function (Cost function) can be
computed for every connected path between the two
end points P & Q.
• Edge quality function should include the average of the
edge strengths of the points (Magnitude and direction
of gradient vector). E S . I N
U N O T
T
K function is complex and the gaps to
• If the edge quality
be evaluated are many and long, heuristic search
algorithm will be computationally expensive.
• It performs well in relatively simple images

Downloaded from Ktunotes.in


Steps in Heuristic Search Algorithm

S . I N
T U N OTE
K

Downloaded from Ktunotes.in


Curve-fitting approach  Iterative End-point fitting

• Suppose there is a group of edge points lying


scattered between 2 particular edge points P and Q.

S . I N
T U N OTE
K

Downloaded from Ktunotes.in


Iterative End-point fitting example 1

S . I N
T U N OTE
K

Downloaded from Ktunotes.in


Iterative End-point fitting example 2

S . I N
T U N OTE
K

Downloaded from Ktunotes.in


Hough Transform (Global Processing Method)

• Used to find out subset of points that lie on a straight line OR


to find out the lines in an image.
• A straight line 𝑦 = 𝑚𝑥 + 𝑐 can be expressed in polar form as
𝜌 = 𝑥 𝑐𝑜𝑠𝜃 + 𝑦 𝑠𝑖𝑛𝜃

S . I N
T U N OTE
K

Downloaded from Ktunotes.in


• For each point (𝑥𝑖 , 𝑦𝑖 ), consider a number of lines
which satisfies the equation 𝜌 = 𝑥𝑖 𝑐𝑜𝑠𝜃 + 𝑦𝑖 𝑠𝑖𝑛𝜃
(Different 𝜌s and 𝜃s)
• If we plot the above equation in 𝜌, 𝜃 plane,

S . I N
T U N OTE
K

Downloaded from Ktunotes.in


• Consider the next point (𝑥𝑗 , 𝑦𝑗 ), If they are on the same line with one
𝜌and one 𝜃.
• So, the 2 curves corresponding to 𝑥𝑖 , 𝑦𝑖 𝑎𝑛𝑑 (𝑥𝑗 , 𝑦𝑗 ) intersect at a
particular 𝜌, 𝜃 .
• That 𝜌, 𝜃 will give the straight line with those 2 points.
• So, our aim is to find out 𝜌, 𝜃 with maximum intersection of sinusoidal
curves so as to determine a line with more number of points

S . I N
T U N OTE
K

Downloaded from Ktunotes.in


Steps for Hough Transform
• Take one point 𝑥𝑖 , 𝑦𝑖 .
• Find 𝜌 = 𝑥𝑖 𝑐𝑜𝑠𝜃 + 𝑦𝑖 𝑠𝑖𝑛𝜃for
different values of 𝜃.
• Map those 𝜌, 𝜃 points as
dots in the accumulator cell
given in figure. S . I N
U N OTE
• Repeat the process for all of
T
K
the points 𝑥𝑖 , 𝑦𝑖 .
• Find the accumulator cell with
maximum entries of 𝜌, 𝜃 .
• That 𝜌, 𝜃 will give the
straight line with maximum
points within it.
Downloaded from Ktunotes.in
Active Contour
• Active contour model, also called snakes, is a framework
in computer vision for delineating an object outline from a
possibly noisy 2D image.
• The curve formed by the connected edge points defines the
active contour.
I N
• It is a set of connected points which interactively move so as
S .
N OTE
to minimise a specified energy function.
T U
K
• Local properties of the image such as gray level, gradient,
etc., contribute to the energy of the snake.
• The snake reacts to the image, but moves in a smooth
continuous manner towards the desired object boundary

Downloaded from Ktunotes.in


Steps involved in greedy-snake Algorithm
• Prepare the image
– Define an energy function which could naturally take on low values
for points located on the actual boundary
– Generate an initial boundary by a segmentation technique such as
thresholding
• Wiggle the snake
S . I N
– Compare the energies of each point on the boundary with the
U N OTE
energies calculated for points in its neighbourhood.
T
K
– For each current boundary point, move the boundary to the
neighbouring point that has the lowest energy.
– Perform this operation once on all points on the boundary to
complete one iteration of the snake algorithm.
– Repeat this iteration until it causes no further movement of the
boundary points.
– When this happens, the snake is said to have ‘converged’ and the
segmentation is complete
Downloaded from Ktunotes.in
• The contour is defined in the (x, y) plane of an image as a
parametric curve
v(s)=(x(s), y(s)) 𝑠 ∈ [0,1]

• The energy function to be minimised is given by

S . I N
T U N OTE
K
• Thus the energy of the snake corresponds to 3 different
forces
– Internal forces b/w points of the contour
– Image forces such as gray level and gradient magnitude that pull the
snake towards the optimal boundary position
– External constraints such as user forces applied to the contour
Downloaded from Ktunotes.in
Internal forces

• 𝐸𝑐𝑜𝑛𝑡 is the continuity term and 𝐸𝑐𝑢𝑟𝑣𝑒 corresponds to the


curvature term.
• Continuity term can be made proportional to the difference
b/w the curve interpoint distance and average interpoint
distance of the entire snake.
S . I N
• This formulation encourages equal spacing of contour points
around the boundary.
T U N OTE
K
• The energy associated with the curvature at a point can be
approximated by taking the square of the magnitude of the
difference b/w 2 adjacent unit tangent vectors.
• This gives a reasonable estimate of the local curvature.
• The continuity measurement of the image energy term can
be simply the result of an edge operator such as Sobel
gradient operator.

Downloaded from Ktunotes.in


Advantages and Disadvantages of Active Contour

• Advantages
– Computational efficiency
– Relative simplicity
• Disadvantages
. I N
– Poor convergence property of the active contour –
S
U N OTE
specifically, concavities in the object of interest are
T
K
rarely covered
– Limited Capture range, which is related to the
initialisation of the snake around the object of interest

Downloaded from Ktunotes.in

You might also like