Professional Documents
Culture Documents
CV Lecture 11
CV Lecture 11
CV Lecture 11
CSC-455
Muhammad Najam Dar
Today’s Lecture
Feature Extractor
Camera (Image Processing) Classifier
Image Analysis
Typical steps:
• Pre-processing
• Segmentation (object
detection)
• Feature extraction
• Feature selection
• Classifier training
• Evaluation of classifier
performance.
Feature types (regional features)
• Colour features
• Gray level
features
• Shape features
• Histogram
(texture) features
Techniques for Image Features
Extraction
• Hough Transform
• Corners
• Shape features
• GLCM
• HOG
• SIFT
• SURF
• Gabor and Wavelet
• LBP
Techniques for Image Features
Extraction
• Hough Transform
• Corners
• Shape features
• GLCM
• HOG
• SIFT
• SURF
• Gabor and Wavelet
• LBP
Properties of Shape Features
3
5. Solidity
• Solidity describes the extent to which the
shape is convex or concave.
14
6. Euler number
• Euler number describes the relation between
the number of contiguous parts and the
number of holes on a shape. Let S be the
number of contiguous parts and N be the
number of holes on a shape. Then the Euler
number is:
Texture Analysis: GLCM Features
Computation of Co-occurrence Matrix
- It has size N×N (N = Number of gray-values) i.e., the
rows & columns represent the set of possible pixel
values.
0 #(0,0)
0 0 1 1 2
0 0 1 1
0 2 2 2
2 2 3 3
Example: Computation (contd.)
0 0 1 1 2 2 1 0
0 0 1 1
Image
0 2 2 2
2 2 3 3
i/j 0 1 2 3 CM for the Image
3
Example: Computation (contd.)
0 0 1 1 2 2 1 0
0 0 1 1 0 2 0 0
Image 0 0 3 1
0 2 2 2
2 2 3 3 0 0 0 1
i/j 0 1 2 3
CM for the Image
0 0 1 1 3 0 2 0
0 0 1 1 0 2 2 0
Image 0 0 1 2
0 2 2 2
2 2 3 3 0 0 0 0
i/j 0 1 2 3
CM for the Image
Co-occurrence Matrices
(d,θ) = (1,)
Angular Second Moment (ASM) feature
Input image Contrast feature Feature
Entropy feature Vector
(d,θ) = (1,) Variance feature
Correlation feature
Inverse Difference Moment (IDM) feature
Sum Average feature
Sum Variance feature
(d,θ) = (1,) Sum Entropy feature
Information Measures of Correlation feature – 1
Information Measures of Correlation feature – 2
(d,θ) =(1,)
ENERGY
• Also called Uniformity or Angular second moment.
• Measures the textural uniformity that is pixel pair
repetitions.
• Detects disorders in textures.
• Energy reaches a maximum value equal to one.
𝐸𝑛𝑒𝑟𝑔𝑦 =∑ ∑ 𝑝
2
𝑖𝑗
𝑖 𝑗
Entropy
•
Contrast
• Measures the spatial frequency of an image
and is difference moment of GLCM.
• It is the difference between the highest and the
lowest values of a contiguous set of pixels.
• It measures the amount of local variations
present in the image.
• Contrast(con)=
Today’s Lecture
x2
x1
Supervised Learning
x2
x1
Classification: Answers are
Categories
Person
Model Trained
Model
Fit
?
What is
Classification?
Which flower is a customer
most likely to purchase based
on similarity to previous
purchase?
?
What is
Classification?
Which flower is a customer
most likely to purchase based
on similarity to previous
purchase?
?
What is
Classification?
Which flower is a customer
most likely to purchase based
on similarity to previous
purchase?
?
Can we LEARN to recognise a rugby player?
190cm
130cm
60kg 90kg
Ballet dancers = tall + skinny?
190cm
130cm
60kg 90kg
Rugby players “cluster” separately in the space.
Height
Weight
What is Needed for Classification?
Katydid or Grasshopper?
For any domain of interest, we can measure
features
Color {Green, Brown, Gray, Has Wings?
Other}
Abdomen Thorax
Length Length Antennae
Length
Mandible
Size
Spiracle
Diameter
Leg Length
My_Collection
We can store
Insect Abdomen Antennae Insect Class
features in a ID Length Length
database. 1 2.7 5.5 Grasshopper
2 8.0 9.1 Katydid
3 0.9 4.7 Grasshopper
The classification
4 1.1 3.1 Grasshopper
problem can now be Katydid
5 5.4 8.5
expressed as: Grasshopper
6 2.9 1.9
7 6.1 6.6 Katydid
•Given a training database
(My_Collection), predict the class 8 0.5 1.0 Grasshopper
label of a previously unseen Katydid
instance
9 8.3 6.6
10 8.1 4.7 Katydids
10
9
8
7
Antenna Length
6
5
4
3
2
1
1 4 5 8
Abdomen Length
6 9
2 7 10
We will return to the
previous slide in two minutes.
In the meantime, we are
going to play a quick game.
3 4 5 2.5
1.5 5 5 2
6 8 8 3
2.5 4.5
Pigeon Problem 1 What class is this
object?
Examples of class A Examples of class
B
3 4 5 2.5 8 1.5
6 8 8 3
4.5
2.5 4.5
7
Pigeon Problem 1 This is a B!
Examples of class A Examples of class
B
3 4 5 2.5 8 1.5
1.5 5 5 2
4 4 5 2.5 8 1.5
6 6 5 3
7 7
3 3 2.5
Pigeon Problem 2
Examples of class A Examples of class
B
5 5 2 5
So this one is an A.
6 6 5 3
7 7
3 3 2.5
Pigeon Problem 3
Examples of class A Examples of class
B
6 6
1 5 7 5
6 3 4 8
3 7 7 7
Pigeon Problem 3 It is a B!
Examples of class A Examples of class
B
6 6
4 4 5 6
The rule is as follows, if the
sum of the two bars is less
than or equal to 10, it is an
1 5 7 5
A. Otherwise it is a B.
6 3 4 8
3 7 7 7
10
Pigeon Problem 1 9
8
Examples of class A Examples of class 7
B 6
Left Bar
5
4
3
2
3 4 5 2.5 1
1 2 3 4
5 Bar
Right 6 7
8 9
1.5 5 5 2 10
2.5 4.5
10
Pigeon Problem 2 9
8
Examples of class A Examples of class 7
B 6
Left Bar
5
4
3
2
4 4 5 2.5 1
1 2 3 4
5 Bar
Right 6 7
8 9
5 5 2 5 10
Let me look it up… here it is..
the rule is, if the two bars
are equal sizes, it is an A.
Otherwise it is a B.
6 6 5 3
3 3 2.5
100
Pigeon Problem 3 90
80
Examples of class A Examples of class 70
B 60
Left Bar
50
40
30
20
4 4 5 6 10
10 20 30 40 50 60 70 80 90 100
Right Bar
1 5 7 5
10
9
8
7
Antenna Length
6
5
4
3
2
1
1 4 5 8
Abdomen Length
6 9
2 7 10
previously unseen instance = 11 5.1 7.0 ???????
1 4 5 8 Katydids
Abdomen Length
6 9 Grasshoppers
Nearest Neighbor Classifier
10
9
8
7
Antenna Length
6
5 If the nearest instance to the
4 previously unseen instance is a
Katydid
3 class is Katydid
2 else
class is
1
Grasshopper
Katydids
1 2 3 4 5 6 7 8 9 10 Grasshopper
Abdomen Length s
Simple Linear Classifier
10
9
8
7 R.A. Fisher
1890-1962
6
5 If previously unseen instance above the
4 line
then
3
class is Katydid
2 else
1 class is Grasshopper
Katydids
1 2 3 4 Grasshopper
5 6 7 s
Which of the “Pigeon Problems” can be solved by
the Simple Linear Classifier? 10
9
8
7
6
5
1) Perfect 4
2) Useless 3
3) Pretty Good 2
1
1 2 3
4 5
100 10 6 7 8
90 9 9 10
Problems that can 80 8
70 7
be solved by a linear 60 6
classifier are call 50 5
linearly separable. 40 4
30 3
20 2
10 1
10 20 30 40 50 60 70 80 90 100 1 2 3
4 5
BINARY vs MULTI-CLASS
CLASSIFICATION
Virginica
A Famous
Problem
R. A. Fisher’s Iris Dataset.
•• 350classes
of each class
Setosa
The task is to classify Iris
Versicolo
plants into one of 3 varieties
r
using the Petal Length and
Petal Width.
Virginica
Setosa
Versicolor
Binary classification: Multi-class
classification:
x2 x2
x1 x1
x2
One-vs-all (one-vs-rest):
x1
x2 x2
x1
x1
x2
Class 1:
Class 2:
Class 3:
x1
Today’s Lecture
40
Age
20
0 10
20
Number of Malignant Nodes
K Nearest Neighbors Classification
60
40
Age
Predict
20
0 10
20
Number of Malignant Nodes
K Nearest Neighbors Classification
Neighbor Count (K = 1): 0 1
60
40
Age
Predict
20
0 10
20
Number of Malignant Nodes
K Nearest Neighbors Classification
Neighbor Count (K = 2): 1 1
60
40
Age
Predict
20
0 10
20
Number of Malignant Nodes
K Nearest Neighbors Classification
Neighbor Count (K = 3): 2 1
60
40
Age
Predict
20
0 10
20
Number of Malignant Nodes
K Nearest Neighbors Classification
Neighbor Count (K = 4): 3 1
60
40
Age
Predict
20
0 10
20
Number of Malignant Nodes
What is Needed to Select a KNN
• Correct value for 'K'
Model?
• How to measure closeness of neighbors?
60
40
Age
20
0 10 20
Number of Malignant
Nodes
Measurement of Distance in KNN
60
40
Age
20
0 10
20
Number of Malignant Nodes
Euclidean Distance
Age
60
24
40 22
Age
20
20
18
1 2 34 5
Number of Surgeries
Scale is Important for Distance
Measurement
"Feature Scaling"
60
40
Age
20
1 2 3 5
4
Number of Surgeries
Scale is Important for Distance
Measurement
"Feature Scaling"
60
40
Nearest
Age
Neighbors!
20
1 2 3 5
4
Number of Surgeries
SOLUTION: Data Normalization
• Between 0 to 1
((x-min(x))/(max(x)-min(x)))
• Between -1 to 1
((x-min(x))/(max(x)-min(x)))*2-1
ISSUE #02: OVERFITTING AND UNDERFITTING
Multiclass decision boundaries break the
data into three or more subsets.
Model Model
Morning Afternoon Evening
Fit
? Model
Is this city Pittsburgh?
What time of day is
Predict it?
(Morning, Afternoon, Evening)
Features and Labels
60
In this case we have:
Two features
• Illumination
Corners
• # corners detected
against background 40
Three labels
• Morning
• Afternoon 20
0 10 20
• Evening Degree of
Illumination
Features and Labels
In this case we have:
60
Two features
• Illumination
Corners
• # corners detected against
background 40
New Example
Three labels known: #illumination, corners
• Morning predict:
morning| afternoon | evening
• Afternoon 20
• Evening 0 10 20
Degree of
Illumination
KNN
#Pixels in Skin
40
If node falls to the left
• Decision = female (blue)
Hue
Note false positive and negatives. 20
0 10
Predict Node
# Rectangular Shapes
Detected
Regression with KNN
K = 20 K=3 K=1
Characteristics of a KNN Model
Hannah 63 200K 1 No
Tom 59 170K 1 No
David 37 50K 2 ?
K-Nearest Neighbour Model
• Example : 3-Nearest
Neighbors
Customer Age
Age Income
Income No. credit
No. credit
cards
cards
Response
Response
John 35
35 35K
35K 3 No
Rachel 22
22 50K
50K 2 Yes
Hannah 63
63 200K
200K 1 No
15.16
Tom 59
59 170K
170K 1 No 15
Nellie 25
25 40K
40K 4 Yes
152.23
David 37 50K 2 ? 15.74 122
37 50K 2 ?
K-Nearest Neighbour Model
• Example : 3-Nearest
Neighbors
Customer Age
Age Income
Income No. credit Response
No. credit
cards
Response cards
John 35
35 35K
35K 3 3 No
No
Rachel 22
22 50K
50K 2 Yes
2
Hannah 63
63 200K
200K 1
Yes No
15.16
59 170K 1 1 No 15
Tom 59 170K
No
25 40K 4 Yes
Nellie 25 40K 152.23
1 122
15.74
37 50K 2
No
2 ?
David 37 50K
Ye?
4
Yes s
Three nearest ones to David are: No, Yes,
Yes
Today’s Lecture
Training Test
What about Folds 2 and 3?
Leave One Out Cross-Validation
Removes one datapoint from the
dataset at a time.
Image # Feature 1 Feature 2 Feature 3 Feature 4 Feature 5 Target
1
2
Train from the N-1 datapoints 3
4
• N = number of datapoints 5
6
7
• In this example, N = 24 8
9
10
11
12
13
This is repeated for each 14
validation 23
24
Prediction
0 1
0
TN FP
Truth
1 FN TP
Training and Test Sets
Training set (actual)
• Fit the model
• Accuracy= (TP+TN)/(P+N)
• Sensitivity or true positive rate (TPR)=
TP/(TP+FN) = TP/P
• Specificity or TNR= TN/(FP+TN) = TN/N
• Positive Predictive value (Precision)
(PPV)= Tp/(Tp+Fp)
• Recall = Tp/(Tp+Fn)
Today’s Lecture
• Calculation of entropy
– Entropy(S) = ∑(i=1 to l)-|Si|/|S| * log2(|Si|/|S|)
• S = set of examples
• Si = subset of S with value vi under the target
attribute
• l = size of the range of the target attribute
Entropy: Weather example
Selecting the Next Attribute
S=[9+,5-] S=[9+,5-]
E=0.940 E=0.940
Humidity Wind
Over
Sunny Rain
cast
135
ID3 Algorithm
[D1,D2,…,D14] Outlook
[9+,5-]
No Yes No Yes
S1
S2
parsing
Speaker Speech
and
Recognition Recognition
arbitration
SK
SN
Process of speech recognition
S1
Switch on
Channel 9
S2
parsing
Speaker Speech
and
Recognition Recognition
arbitration
SK
SN
Process of speech recognition
S1
Who is
speaking?
S2
parsing
Speaker Speech
and
Recognition Recognition
arbitration
SK
Annie SN
David
Cathy
“Authentication”
Process of speech recognition
S1
What is he
saying?
S2
parsing
Speaker Speech
and
Recognition Recognition
arbitration
SK
SN
On,Off,TV
Fridge,Door
“Understanding”
Process of speech recognition
What is he S1
talking
about?
S2
parsing
Speaker Speech
and
Recognition Recognition
arbitration
SK
“Switch”,”to”,”channel”,”nine” SN
Channel->TV
Dim->Lamp
On->TV,Lamp
“Inferring and execution”
Phases of the Project:
Phase 1: Creating a specific data set (0 - 9).
Zero (0)
One (1)
Two (2)
Three (3)
Four (4)
Five (5)
Six (6)
Seven (7)
Eight (8)
Nine (9)
References
Some Slide material has been taken from Dr . M. Usman Akram Computer Vision
Lectures
CSCI 1430: Introduction to Computer Vision by James Tompkin
Statistical Pattern Recognition: A Review – A.K Jain et al., PAMI (22) 2000
Pattern Recognition and Analysis Course – A.K. Jain, MSU
Pattern Classification” by Duda et al., John Wiley & Sons.
Digital Image Processing”, Rafael C. Gonzalez & Richard E. Woods, Addison-Wesley, 2002
Machine Vision: Automated Visual Inspection and Robot Vision”, David Vernon, Prentice Hall, 1991
www.eu.aibo.com/
Advances in Human Computer Interaction, Shane Pinder, InTech, Austria, October 2008
Computer Vision A modern Approach by Frosyth
http://www.cs.cmu.edu/~16385/s18/
Introduction to Machine Learning, Alphaydin
Statistical Pattern Recognition: A Review – A.K Jain et al., PAMI (22) 2000
Pattern Recognition and Analysis Course – A.K. Jain, MSU
Pattern Classification” by Duda et al., John Wiley & Sons.
http://www.doc.ic.ac.uk/~sgc/teaching/pre2012/v231/lecture13.html
Some Material adopted from Dr. Adam Prugel-Bennett Dr. Andrew Ng and Dr. Aman ullah’s Slides