Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

Dr.Azmi T.

Al-Rawi
University of Anbar\ College Of Computer Science& I.T
Graduate studying (Master)
Lec.10
2- Clustering methods.
The clustering techniques can be applied to any domain, such as
any N-dimensional color or feature space, whose components may even
include the spatial domain’s (r,c) coordinates.
The region growing and shrinking category can be considered a subset
of the clustering methods, but is limited to the spatial domain.
What is clustering?
 Organizing data into classes such that:
– High intra-class similarity.
– Low inter-class similarity.
 Finding the class labels and the number of classes directly from the
data (as opposed to classification tasks).
What is similarity?
Cluster by features
• Color • Intensity • Location • Texture.
There are different methods and one of the most popular methods is K-
Means clustering algorithm.
The objective of K-Means clustering is to minimize the sum of squared
distances between all points and the cluster center.
Steps in K-Means algorithm:
1. Choose the number of clusters K.
2. Select at random K points, the centroids(not necessarily from your
dataset).
3. Assign each data point to the closest centroid → that forms K clusters.
4. Compute and place the new centroid of each cluster.

1
Dr.Azmi T.Al-Rawi
University of Anbar\ College Of Computer Science& I.T
Graduate studying (Master)
Lec.10
5. Reassign each data point to the new closest centroid. If any
reassignment. took place, go to step 4, otherwise. See fig.1
How K-Means Clustering Algorithm works?

start

Number of
clustring K

Centroid
No. objects End
move
Distance from
group
objects to centroid

Grouping based on
minimum distance

Example: The data are: (2,3,4,10,11,12,20,25,30)


Solution: we find two groups k=2
The individual values:m1=4, m2=12
Data D1 D2 Clust.
2 2 10 K1
3 1 9 K1
4 0 8 K1
10 6 2 K2
11 7 1 K2
12 8 0 K2
20 16 8 K2
25 21 13 K2

2
Dr.Azmi T.Al-Rawi
University of Anbar\ College Of Computer Science& I.T
Graduate studying (Master)
Lec.10
30 26 8 K2

m1=(2+3+4)/3 =3, m2=(10+11+12+20+25+30)/6 =108/6 =18


Data D1 D2 Clust.
2 1 16 K1
3 0 15 K1
4 1 14 K1
10 7 8 K1
11 8 7 K2
12 9 6 K2
20 17 2 K2
25 22 7 K2
30 27 12 K2

m1=(2+3+4+10)/4 =4.75≈5
m2=(11+12+20+25+30)/5=19.6≈20
Data D1 D2 Clust.
2 3 18 K1
3 2 17 K1
4 1 16 K1
10 5 10 K1
11 6 9 K1
12 7 8 K1
20 15 0 K2
25 20 5 K2
30 25 10 K2

3
Dr.Azmi T.Al-Rawi
University of Anbar\ College Of Computer Science& I.T
Graduate studying (Master)
Lec.10

m1=(2+3+4+10+11+12)/6 =7, m2=(20+25+30)/3 =25


Data D1 D2 Clust.
2 5 23 K1
3 4 22 K1
4 3 21 K1
10 3 15 K1
11 4 14 K1
12 5 13 K1
20 13 5 K2
25 18 0 K2
30 23 5 K2
we stope when the means are become same at any operation

Before Clustering After Clustering


40 25
30 20 k1
15 k2
20
10
10 5
0 0
0 2 4 6 8 10 0 5 10 15 20 25

3-Boundary detection.
The boundary detection methods are extensions of the edge detection
techniques and differ from the other segmentation methods by finding the
segmented regions indirectly by finding their borders.
Edge and line detection are important steps in one category of image
segmentation methods.

4
Dr.Azmi T.Al-Rawi
University of Anbar\ College Of Computer Science& I.T
Graduate studying (Master)
Lec.10

Edge/Line Detection:
The edge and line detection operators presented here represent the various
types of operators in use today.
These based on discrete approximations to differential operators.
 Differential operations measure the rate of change in an image
brightness function.
 A large change in image brightness over a short spatial distance
indicates the presence of an edge.
 Edge detection is also used to find complex object boundaries by
marking potential edge points corresponding to places in an image
where rapid changes in brightness occur.
Edge detection is a fundamental tool in image processing, machine
vision and computer vision, particularly in the areas of feature
detection, feature extraction, determine of shape & size, and use in
image sharpening and enhancement.

Definitions:
 Edge is area of signification changes in the image intensity
/contrast.
 Edge detection is a location area with strong intensity contrast.
Types of edges:(variation of intensity gray level):As shown in fig.2
1-Step edge
2-Ramp edge
3- Line edge
5
Dr.Azmi T.Al-Rawi
University of Anbar\ College Of Computer Science& I.T
Graduate studying (Master)
Lec.10
4- Roof edge

Figure 2: Gray values across edges

Steps of edge detection:


-Filtering: Filtering image to improve performance of the edge detection
noise
-Enhancement: Emphasize pixels having significant change in local
intensity
-Detection: Identify edge –Thresholding
-Localization: Locate the edge accurately, Estimate edge orientation

Methods of edge detection:


There is a very large amount of edge detection techniques available, each
technique designed to be perceptive to certain types of edges:
First order derivative /gradient methods:
1-Roberts Edge Detection.
2-Sobel Edge Detection.
3-Prewitt Edge Detection:

6
Dr.Azmi T.Al-Rawi
University of Anbar\ College Of Computer Science& I.T
Graduate studying (Master)
Lec.10
Second order derivative /gradient methods:
1-Laplacian
2-Laplacian of Gaussian
3-Different of Gaussian
Optimal edge detection:
Canny Edge Detection

First order derivative /gradient methods:


At the point of greatest slope.
The first derivative has maximum value. eg. for continuous 1-dimensional
function f(x)
𝜕𝑓
𝑔𝑥 𝜕𝑥
( )
∇𝑓 = 𝑔𝑟𝑎𝑑 𝑓 = [𝑔 ] = [𝜕𝑓 ]
𝑦
𝜕𝑦

The magnitude of ∇𝑓

𝑀(𝑥 ) = 𝑚𝑎𝑔(∇𝑓 ) = √𝑔𝑥2 + 𝑔𝑦2

The direction of ∇𝑓
𝑔
𝛼(𝑥, 𝑦) = 𝑡𝑎𝑛−1 [ 𝑥 ]
𝑔𝑦

The direction of the edge:

7
Dr.Azmi T.Al-Rawi
University of Anbar\ College Of Computer Science& I.T
Graduate studying (Master)
Lec.10
𝜕𝑓
𝑔𝑥 𝜕𝑥
 Edge normal:∇𝑓 = 𝑔𝑟𝑎𝑑 (𝑓 ) = [𝑔 ] = [𝜕𝑓 ]
𝑦
𝜕𝑦
 Edge unit normal: ∇𝑓/𝑚𝑎𝑔(∇𝑓)
in paratactic, sometimes the magnitude is approximated by
𝜕𝑓 𝜕𝑓
𝑚𝑎𝑔(∇𝑓 ) = | + |
𝜕𝑥 𝜕𝑦
𝜕𝑓 𝜕𝑓
𝑚𝑎𝑔(∇𝑓 ) = 𝑚𝑎𝑥 (| | , | |)
𝜕𝑥 𝜕𝑦

Approximation of gradient for a discrete two dimensional function


Gx ≅ 𝑓 (𝑖, 𝑗 + 1) − 𝑓(𝑖, 𝑗)
Gy ≅ 𝑓 (𝑖, 𝑗) − 𝑓(𝑖 + 1, 𝑗)
Convolution mask:

Roberts Edge Detection:


This method emphasizes regions of high spatial frequency which often
correspond to edges.

-1 0 0 -1
Gx= , Gy = 1 0
0 1

Sobel Edge Detection:

8
Dr.Azmi T.Al-Rawi
University of Anbar\ College Of Computer Science& I.T
Graduate studying (Master)
Lec.10
The Sobel method of edge detection for image segmentation finds edges
using the Sobel approximation to the derivative
it is used to find the estimated absolute gradient magnitude at each point
in n input grayscale image

-1 -2 -1 -1 0 1
Gx = 0 0 0 , Gy = -2 0 2
1 2 1 -1 0 1

Prewitt Edge Detection:


To estimate the magnitude and orientation of an edge Prewitt is a correct
way.
-1 -1 -1 -1 0 1
Gx = 0 0 0 Gy = -1 0 1
1 1 1 -1 0 1

So if Gx and were the grey values produced by applying Gy and to an


image, then the output grey value can be chosen by any of these methods
1. 𝑣 = 𝑚𝑎𝑥{|𝑔𝑥 |, |𝑔𝑦 |}
2. 𝑣 = |𝑔𝑥 | + 𝑔𝑦 |

3. 𝑣 = √𝑔𝑥2 + 𝑔𝑦2

Second order derivative /gradient methods:


LoG Edge Detection:
The Laplacian of Gaussian (LoG). The LoG of an image f(x,y) is a second
order derivative defined as

9
Dr.Azmi T.Al-Rawi
University of Anbar\ College Of Computer Science& I.T
Graduate studying (Master)
Lec.10
2 2
𝜕 𝑓 𝜕 𝑓
∇2 𝑓 = +
𝜕𝑥 2 𝜕𝑦 2
which yields a double edge image? Locating edges then consists of
finding the zero crossings between the double edges.

0 -1 0 -1 -1 -1
Gx= -1 4 -1 Gy = -1 8 -1
0 -1 0 -1 -1 -1

Example: Applied Prewitt gradient Gy to the image A


3 0 1 2 7 4
1 5 8 9 3 1
2 7 2 5 1 3
0 1 3 1 7 8
4 2 1 6 2 8
2 4 5 2 3 9
-1 0 1
-1 0 1
-1 0 1
The image After applied Gy
-5 -4 0 8
-10 -2 2 3
0 -2 -4 -7
-3 -2 -3 -16

Summary:
-Threshold is the simplest way of segmentation

10
Dr.Azmi T.Al-Rawi
University of Anbar\ College Of Computer Science& I.T
Graduate studying (Master)
Lec.10
-Region based methods are based on continuity.
-The cluster is referred to as the region in addition to group the regions
according to their anatomical or functional roles are the goal of the image
segmentation.
Edge detection techniques are generally used for finding discontinuities
in gray level images.
Image segmentation methods for detecting discontinuities are boundary
based methods.
figure 3 shows the applications of edge detection

Figure 3: Original Image with the result of various edge detection


techniques

11
Dr.Azmi T.Al-Rawi
University of Anbar\ College Of Computer Science& I.T
Graduate studying (Master)
Lec.10

References:
1-International Journal of Computer Science & Information Technology (IJCSIT) Vol 3,
No 6, Dec 2011.

2-Digital Image Processing and Analysis: Application with MATLAB and CVIPtools, 3rd
Edition, SE Umbaugh, Taylor&Francis/CRC Press, 2018.
3-Alasdair McAndrew, An Introduction to Digital Image Processing with Matlab Notes for
SCM2511 Image Processing 1.

12

You might also like