Module 3
Module 3
image processing
S5 Minor
Similarity: to partition an image into regions that are similar according to a set
of predefined criteria.
Region-based segmentation
Classification of segmentation based on the
image area of consideration
Local Segmentation
– Segmenting sub-images which are small windows on a whole image
– Number of pixels available will be lower than the global segmentation
Global Segmentation
– Concerned with segmenting a whole image
– Global segmentation deals with segments consisting of a relatively large number of pixels
Image Segmentation Approaches
Region approach
– Each pixel is assigned to a particular object or region.
Boundary approach
– Attempts to locate directly the boundaries that exist between the regions
Edge approach
– Edges are identified first, and are linked together to form required boundaries
Region Based Segmentation
• Region –an aggregation of pixels with common properties
• Properties like gray level, color, texture, shape help to identify regions and
similarity of such properties, is used to build groups of regions having a
particular meaning.
• Region-based segmentation is based on the connectivity of similar
pixels in a region.
• 2 main approaches to region-based segmentation:
– Region growing
– Region splitting and merging
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.
• 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 properties similar to the seed
(specified ranges of gray level or colour)
• Once the region is identified, a new seed is chosen from the remaining pixels and the
process is repeated. This continues until all pixels have been allocated to a segment
Larger quadregions
lead to block-like
segmentation.
32x32
Smaller quadregions
lead to small black
regions.
16x16 seems to be
the best result.
16x16 8x8
Apply split and merge segmentation to the following image and show the quadtree
Clustering Based Segmentation
• The clustering technique attempts to access the relationships among patterns of the
data set by organising the patterns into groups or clusters such that patterns within a
cluster are more similar to each other than patterns belonging to different clusters.
• Clustering refers to the classification of objects into groups according to certain
properties of these objects.
• In the clustering technique, an attempt is made to extract a feature vector from local
areas in the image.
• A standard procedure for clustering is to assign each pixel to the class of the nearest
cluster mean.
• Clustering : two categories
• hierarchical
• Partitional
• Within each category, there exist many types of algorithms for finding clusters.
23
Rajagiri School of Engineering & Technology, Kochi
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.
The end result is a tree of clusters representing the nested group of patterns and
similarity levels at which groupings change.
The clustering methods differ in regard to the rules by which two small clusters are
merged or a large cluster is split.
two main categories of algorithms used in the hierarchical clustering framework are
Agglomerative
divisive
Agglomerative Clustering
("bottom-up") Root abcd
25
Agglomerative Clustering Algorithm
• More popular hierarchical clustering technique
• Basic algorithm is straightforward
1. Compute the distance matrix
2. Let each data point be a cluster
3. Repeat
4. Merge the two closest clusters
5. Update the distance matrix
6. Until only a single cluster remains
http://jcsites.juniata.edu/faculty/rhodes/ml/hiercluster.htm
2
6
How to Define Inter-Cluster Distance
p1 p2 p3 p4 p5 . ..
p1
Distance?
p2
p3
p4
p5
⚫ MIN
.
⚫ MAX
. Distance Matrix
⚫ Group Average .
⚫ Distance Between Centroids
27
Single Link Algorithm
– The distance between two clusters is represented by the distance of the
closest pair of data objects belonging to different clusters.
– Determined by one pair of points, i.e., by one link in the proximity graph
– merges two clusters according to the minimum distance between the data
samples from two clusters .
– The algorithm allows for a tendency to produce clusters with elongated
shapes
Complete Link Algorithm
• The distance between two clusters is represented by the distance of the
farthest pair of data objects belonging to different clusters
• Incorporates the maximum distance between data samples in clusters,
but its application always results in compact clusters
2
9
Minimum-variance algorithm (Ward’s method)
Ward’s method (a.k.a. Minimum variance method or Ward’s Minimum Variance Clustering
Method) is an alternative to single-link clustering.
Ward’s method starts with n clusters, each containing a single object. These n clusters are
combined to make one cluster containing all objects. At each step, the process makes a
new cluster that minimizes variance, measured by an index called E (also called the sum of
squares index).
Calculate the distance between each object in a particular cluster, and that cluster’s
mean.
32
K means Clustering:
• Simplest method of unsupervised learning
• Groups the unlabeled dataset into different clusters.
• K stands for the number of clusters (user input to algorithm) i.e K=2, there
will be two clusters, and for K=3, there will be three clusters, and so on
• It is a centroid-based algorithm, where each cluster is associated with a
centroid. T
33
K-means Clustering Algorithm
• Randomly choose K data points to be initial cluster centres (centroids)
• Assign each data point to the closest cluster centre
• Recompute the cluster centres using the current cluster membership
• Repeat the procedure from step 2 until the convergence criterion is met
Stopping/ Convergence Criterion
f
= f ( x +1) − f ( x )
x
f
2
= f ( x +1) + f ( x −1) − 2 f ( x )
x2
Gradient Operator
-1 0 0 -1
0 1 1 0
𝑮𝒙 𝑮𝒚
Horizontal Vertical
-1 -1 -1 -1 0 1
0 0 0 -1 0 1
3 X 3 region of an image 1 1 1 -1 0 1
with intensity values
𝑮𝒙 𝑮𝒚
Horizontal Vertical
Common Masks for Computing Gradient
Sobel Mask: Similar to Prewitt mask, the center pixels around the edge region
are given more weightage.
-1 -2 -1 -1 0 1
Sobel masks are preferred because of
0 0 0 -2 0 2 better noise suppression characteristics
3 X 3 region of an image 1 2 1 -1 0 1
with intensity values
𝑮𝒙 𝑮𝒚
Horizontal Vertical
Example
-2 0 2
-1 0 1
1 2 5 2
Gy 13
2 1 6 9
132 + 32 =13.34
3 3 4 9
1 0 1 8
-1 -2 -1
0 0 0
1 2 1 -1*1 +2*-2 +5*-1 +….. +3*2 +4*1 =3
Gx
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
1st derivative and equate to zero.
•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.
27
Laplacian operator
Obtained by taking dot product of ∇ with itself
2 f 2 f
2 f = +
x2 y2
Application: Laplacian mask can be used
to detect an isolated point in an image
• Using the Laplacian mask, a point can be detected at the location (x,y) on
which the mask is centered, if the absolute value of the response of mask at
that point exceeds a specific threshold
• The output is obtained as:
𝜕 2𝐺 𝜕 2𝐺
∇2𝐺 = 2
+ 2
𝜕𝑥 𝜕𝑦
− 𝑥 2 +𝑦 2
1 𝑥 2 +𝑦 2 −2𝜎 2
∇2𝐺 = 𝑒 2𝜎 2
𝜎4
2𝜋𝜎 2
−[𝑥 2 +𝑦 2 ] −[𝑥 2 +𝑦 2 ]
1 2 1 2
𝐷𝑜𝐺 𝑥, 𝑦 = 𝑒 2𝜎1 − 𝑒 2𝜎2
2𝜋𝜎12 2𝜋𝜎22
with 𝜎1 > 𝜎2
• If the ratio of standard deviation is 1.6 ∶ 1, it gives a good approximation to LoG
Canny Edge Detector
Canny Edge Detection is based on 3 basic objectives:
1. Low Error Rate: All edges must be found and edges detected must be close to the
true edge.
2. Edge points must be well localized: The distance between point marked as an
edge by detector and centre of true edge must be minimum
3. Single edge point response: The detector should return only one point for each true
edge point
➢ One problem with a Laplacian zero-crossing as an edge detector is that it simply adds the
principal curvatures together. That is, it does not really determine the maximum of the
gradient magnitude. The Canny edge detector defines edges as zero-crossings of second
derivatives in the direction of the greatest first derivative.
Steps Involved in Canny Edge Detection
Let 𝑓(𝑥, 𝑦) denote the original image and 𝐺(𝑥, 𝑦) denote the 2D Gaussian function
1 −[𝑥 2 +𝑦 ]2
𝐺 𝑥, 𝑦 = 2
𝑒 2𝜎 2
2𝜋𝜎
Step 1: Apply Gaussian filter to smooth the image in order to remove the noise
2D first
derivative operator is
Step 2: Now compute gradient magnitude and direction (angle) of the image applied to the smoothed
• All pixels are candidates for linking and have to be accepted or eliminated based
on predefined global properties.
Hough Transform : used to find subset of points that lie on a straight line
Thus the locus of all such lines in the x, y space is a sinusoid in parameter space and
any point in the x, y plane corresponds to a particular sinusoidal curve in the ρ, θ
space.
Suppose we have a set of edge points xi, yi that lie along a straight line having
parameters ρ0, θ0.
Each edge point plots to a sinusoidal curve in the ρ, θ space, but these curves must
intersect at a point ρ0, θ0 since this is a line they all have common.
• In Hough transform, generally we consider the normal representation of line,
ρ = 𝑥𝑐𝑜𝑠𝜃 + 𝑦𝑠𝑖𝑛𝜃
A cell at coordinate
(𝑖, 𝑗) with
accumulator value
𝐴(𝑖, 𝑗) corresponds
to parameter space
coordinates (𝜌𝑖 , 𝜃𝑗 )
• For every point (𝑥𝑘 , 𝑦𝑘) and find 𝜌 = 𝑥𝑘𝑐𝑜𝑠𝜃 + 𝑦𝑘𝑠𝑖𝑛𝜃 for different values of 𝜃.
• The accumulator value corresponding to obtained value of 𝜌 and 𝜃 is incremented by one.
For example: if we obtain 𝜌𝑝, 𝜃𝑞 , the count in the corresponding accumulator cell 𝐴(𝑝, 𝑞) is
incremented by one.
• Repeat the process for all of the points (𝑥𝑖 , 𝑦𝑖) in the image .
• Suppose 𝐴(𝑖, 𝑗) has a value of P, it means that there are P points in x-y plane on line
ρ𝑖 = 𝑥𝑐𝑜𝑠𝜃𝑗 + 𝑦𝑠𝑖𝑛𝜃𝑗
https://www.youtube.com/watch?v=CeU_yZjdVqY
Greedy-Snake Algorithm
The steps involved in a greedy-snake algorithm are given below.
A. Prepare the Image.
1. Define an energy function which could naturally take on low values for points located on the
actual boundary.
2. Generate an initial boundary by a segmentation technique such as thresholding.
B. Wiggle the Snake.
1. Compare the boundary of each point on the boundary with the energies calculated for points in
its neighbourhood.
2. For each current boundary point, move the boundary to the neighbouring point that has the
lowest energy.
3. Perform this operation once on all points on the boundary to complete one iteration of the snake
algorithm.
4. Repeat this iteration until it causes no further movement of the boundary points.
5. When this happens, the snake is said to have ‘converged’ and the segmentation is complete.
The choice of the energy function to be minimised determines the behaviour of
the algorithm.
The energy function is given by
(ii) The second problem with snakes is the limited capture range, which is
related to the initialisation of the snake around the object of interest.
THRESHOLDING
• Image partitioning into regions directly from their
intensity values.
Noise in Thresholding
Difficulty in determining the threshold due to noise
Thresholded Image
Original Image
If you get the threshold wrong the results can be disastrous
1 + 2
T=
2
5. Repeat steps 2 – 4 until the difference in T in successive iterations is less than a
predefined limit T∞
This algorithm works very well for finding thresholds when the histogram is
suitable
Thresholding Example 1
Thresholding Example 2
Single Value Thresholding and Illumination
1 1
m(k +1) = zi = m(k) + (z k +1 − zk −n )
n i=k +2−n n
n is the number of points used in the average
• Segmentation is then performed at each point comparing
the pixel value to a fraction of the moving average.
Shaded text images Otsu Moving averages
occur typically from
photographic flashes
Sinusoidal variations (the Otsu Moving averages
power supply of the scanner
not grounded properly)
• However it is not reliable for threshold selection when peaks are not clearly
resolved.
• A criterion function is calculated for each intensity and that which maximizes this
function is chosen as the threshold.
Image Histogram