IT5409 Ch4 Part2 Feature ExtractionMatching
IT5409 Ch4 Part2 Feature ExtractionMatching
Computer Vision
Chapter 4: Feature detection and Image
matching
Plan
• Edges
‒ Detection
‒ linking
• Feature extraction
‒ Global features
‒ Local features
‒ Matching
• Applications
1
4/25/2023
Feature extraction
• Global features
• Color / Shape / Texture
• Local features
2
4/25/2023
Global features?
How to distinguish these objects?
Types of features
• Contour representation, Shape features
• Color descriptors
• Texture features
3
4/25/2023
Color features
• Histogram 256 bins intensity histogram 16 bins intensity histogram
Distance / Similarity
• L1 ou L2 (euclidian) distances are often used
N
d L1 (H, G) hi g i
i 1
• Histogram intersection
∑ min( ℎ , 𝑔 )
∩ (H,G) =
∑ 𝑔
4
4/25/2023
Advantages of histogram
• Invariant to basic geometric transformations:
‒ Rotation
‒ Translation
‒ Zoom (Scaling)
Some inconveniences
• The similarity between colors in
adjacent colors (bin) is not taken
into account
10
5
4/25/2023
Some inconveniences
• Background effect: d(I1,I2) ? d(I1, I3)
I3
I1
I2
11
Texture features
• A texture can be defined as
‒ a region with variation of intensity
‒ as a spatial organization of pixels
12
6
4/25/2023
Texture features
• There are several methods for analyzing textures:
‒ First order statistics
• Statistics on histogram
‒ Co-occurence matrices
• Searching patterns
‒ Frequential analysis
• Gabor filter
‒…
• The most difficult is to find a good representation (good
parameters) for each texture
13
Texture features
14
7
4/25/2023
is.hust.edu.vn 15
is.hust.edu.vn 16
8
4/25/2023
Matrix of size Ng x Ng
Ng is the number of gray level in the image (256x256)
We often reduce that number to 8x8, 16x16 or 32x32
GLCM
card ({ p1 , p2 I ( p1 ) ci , I ( p2 ) c j , N d , ( p1 , p2 ) true})
CM d , (ci , c j )
card ({ p1, p 2 N d , ( p1 , p2 ) true})
18
9
4/25/2023
GLCM
Example on how to compute these matrices:
1 2 3 4
1 4 4 3
1 ? ? ? ?
4 2 3 2
2 ? ? ? ?
1 2 1 4
3 ? ? ? ?
1 2 2 3
4 ? ? ? ?
Image
Matrix for distance=1
and direction=0°
We loop over the image and for each pair of pixels following the given
distance and orientation, we increment the co-occurence matrix
GLCM
Example on how to compute these matrices:
1 2 3 4
1 4 4 3
1 0 0 0 1
4 2 3 2
2 0 0 0 0
1 2 1 4
3 0 0 0 0
1 2 2 3
4 0 0 0 0
Image
Matrix for distance=1 and
direction=0°
10
4/25/2023
GLCM
Example on how to compute these matrices:
1 2 3 4
1 4 4 3
1 0 0 0 1
4 2 3 2
2 0 0 0 0
1 2 1 4
3 0 0 0 0
1 2 2 3
4 0 0 0 1
Image
Matrix for distance=1 and
direction=0°
GLCM
Example on how to compute these matrices:
1 2 3 4
1 4 4 3
1 0 0 0 1
4 2 3 2
2 0 0 1 0
1 2 1 4
3 0 1 0 0
1 2 2 3
4 0 1 1 1
Image
Matrix for distance=1 and
direction=0°
11
4/25/2023
GLCM
Example on how to compute these matrices
(final):
1 2 3 4 1 2 3 4
1 4 4 3
1 0 2 0 2 1 0 2 1 0
4 2 3 2
2 1 1 2 0 2 1 1 0 0
1 2 1 4
3 0 1 0 0 3 0 0 0 1
1 2 2 3
4 0 1 1 1 4 0 2 1 0
Image
Matrix for distance=1 Matrix for distance=1
and direction=0° and direction=45°
GLCM
• Most important/populer parameters computed from
GLCM:
Energy CM d 2 (i, j ) minimal when all elements are equal
i j
entropy CM d (i, j ) log(CM d (i, j ))
i j a measure of chaos,
maximal when all elements are equal
contrast (i j ) 2 CM d (i, j )
small values when big elements
i j are near the main diagonal
1
idm CM d (i, j )
i j 1 (i j ) 2 idm (inverse differential moment) has small
values when big elements are far from the
main diagonal
is.hust.edu.vn 24
12
4/25/2023
GLCM
• Haralick features:
‒ For each GLCM, we can compute up to 14 (13)
parameters characterizing the texture, of which the most
important : mean, variance, energy, inertia, entropy,
inverse differential moment
‒ Ref: http://haralick.org/journals/TexturalFeatures.pdf
is.hust.edu.vn 25
Invariances
• Rotation?
‒ Average on all directions
• Scaling?
‒ Multi-resolutions
26
13
4/25/2023
Source : William Robson Schwartz et al. Evaluation of Feature Descriptors for Texture Classification – 2012 JEI
is.hust.edu.vn 27
Shape features
• Contour-based features
‒ Chain coding, polygone approximation, geometric
parameters, angular profile, surface, perimeter, …
• Region based:
‒ Invariant moments, …
28
14
4/25/2023
Shape features
29
30
15
4/25/2023
31
𝑀 , ,𝑀 , = 𝑐𝑒𝑛𝑡𝑟𝑜𝑖𝑑 𝑜𝑓 𝐷
• Central moments:
Invariant to
translation
32
16
4/25/2023
invariant to
translation,
scale, and
rotation, and
reflection
Change for
image
reflection
33
https://www.learnopencv.com/wp-content/uploads/2018/12/HuMoments-Shape-Matching.png
34
17
4/25/2023
Shape Context
https://www2.eecs.berkeley.edu/Research/Projects/CS/vision/shape/sc_digits.html
is.hust.edu.vn 35
Examples: PHOG
PHOG:
Pyramid Histogram of Oriented Gradients
Source:http://www.robots.ox.ac.uk/~vgg/research/caltech/phog.html
36
18
4/25/2023
Feature extraction
• Global features
• Local features
• Interest point detector
• Local descriptor
37
38
19
4/25/2023
Image matching
by swashford
by Diva Sian
39
Harder Still?
40
20
4/25/2023
41
D. Lowe 2002
42
21
4/25/2023
‒ Articulation d dq
φ
φ
θq
θ
‒ Intra-category variations
Source: CS131 - Juan Carlos Niebles and Ranjay Krishna
43
22
4/25/2023
45
23
4/25/2023
A1 2. Define a region
around each keypoint
A2 A3
3. Extract and
normalize the region content
47
24
4/25/2023
Local features
• Objectifs:
• Look for similar objects/regions
• Partial query
Look for pictures that contain sunflowers
• Solution:
• Describing local regions
• Adding spatial constraints if need
49
Dividing into
patches with Keypoint detection
regular grid
Image segmentation
50
25
4/25/2023
Common Requirements
• Problem 1:
‒ Detect the same point independently in both images
No chance to match!
We need a repeatable detector!
• Problem 2:
‒ For each point correctly recognize the corresponding one
52
26
4/25/2023
53
54
27
4/25/2023
Requirements
• Region extraction needs to be repeatable and accurate
‒ Invariant to translation, rotation, scale changes
‒ Robust or covariant to out-of-plane (affine) transformations
‒ Robust to lighting variations, noise, blur, quantization
55
Main questions
• Where will the interest points come from?
‒ What are salient features that we’ll detect in multiple
views?
• How to describe a local region?
• How to establish correspondences, i.e.,
compute matches?
56
28
4/25/2023
Feature extraction
• Global features
• Local features
• Interest point detector
• Local descriptor
• Matching
57
58
29
4/25/2023
59
60
30
4/25/2023
Keypoint Localization
• Goals:
‒ Repeatable detection
‒ Precise localization
‒ Interesting content
Look for two-
dimensional signal
changes
61
Finding Corners
• Key property:
‒ In the region around a corner, image gradient has two or
more dominant directions
• Corners are repeatable and distinctive
C.Harris and M.Stephens. "A Combined Corner and Edge Detector.“ Proceedings of the 4th Alvey
Vision Conference, 1988.
62
31
4/25/2023
63
Large
Corner
Large
Small
Edge
Large
Small
Nothing
Small
64
32
4/25/2023
E (u , v) w( x, y ) I ( x u , y v) I ( x, y )
2
x, y
or
Window function w(x,y) =
E (u , v) w( x, y ) I ( x u , y v) I ( x, y )
2
x, y
I(x, y)
E(u, v)
E(0,0)
w(x, y)
66
33
4/25/2023
E (u , v) w( x, y ) I ( x u , y v) I ( x, y )
2
x, y
I(x, y)
E(u, v)
E(3,2)
w(x, y)
67
E (u , v) w( x, y ) I ( x u , y v) I ( x, y )
2
x, y
68
34
4/25/2023
E (u , v) w( x, y ) I ( x u , y v) I ( x, y )
2
x, y
69
70
35
4/25/2023
Ignore function
value; set to 0 Ignore first Just look at
derivative, shape of
set to 0 second
derivative
71
Euu (u, v) 2 w( x, y )I x ( x u , y v) I x ( x u, y v )
x, y
Euv (u, v) 2 w( x, y )I y ( x u, y v ) I x ( x u, y v)
x, y
36
4/25/2023
73
E (u , v) w( x, y ) I ( x u , y v) I ( x, y )
2
x, y
74
37
4/25/2023
u
E (u, v) [u v] M
v
where M is a 22 matrix computed from image derivatives:
M
Slide credit: Rick Szeliski
75
I x2 I I x y
1 0
M
I x I y I 0 2
2
y
Image I Ix Iy IxIy
76
38
4/25/2023
I x2 I I x y
1 0
M
I x I y I 0 2
2
y
• This means:
‒ Dominant gradient directions align with x or y axis
‒ If either λ is close to 0, then this is not a corner, so look for
locations where both are large.
77
General case
• Since M is symmetric, we have 0
M R 1 1 R
0 2
(Eigenvalue decomposition)
Direction of the
slowest change
(max)-1/2
(min)-1/2
78
39
4/25/2023
2 “Edge”
2 >> 1
“Corner”
1 and 2 are large, 1 ~ 2;
E increases in all directions
79
• Fast approximation
‒ Avoid computing the “Flat” “Edge”
eigenvalues region θ<0
‒ α: constant 1
(0.04 to 0.06)
Slide credit: Kristen Grauman
80
40
4/25/2023
I2 IxI y
M g ( ) x
Gaussian I x I y I y2
‒ Result is rotation invariant
81
3. Gaussian
filter g(I)
g(Ix2) g(Iy2) g(IxIy)
82
41
4/25/2023
42
4/25/2023
43
4/25/2023
88
44
4/25/2023
89
90
45
4/25/2023
91
92
46
4/25/2023
Exhaustive search
• Multi-scale approach
93
Invariance
• Extract patch from each image individually
94
47
4/25/2023
scale = 1/2
f Image 1 f Image 2
scale = 1/2
s1 s2 region size
region size
96
48
4/25/2023
Same operator responses if the patch contains the same image up to scale
factor.
K. Grauman, B. Leibe
97
Example
Function responses for increasing scale (scale signature)
K. Grauman, B. Leibe
f ( I i1im ( x, )) f ( I i1im ( x, ))
98
49
4/25/2023
Example
Function responses for increasing scale (scale signature)
K. Grauman, B. Leibe
f ( I i1im ( x, )) f ( I i1im ( x, ))
99
Example
Function responses for increasing scale (scale signature)
K. Grauman, B. Leibe
f ( I i1im ( x, )) f ( I i1im ( x, ))
100
50
4/25/2023
Example
Function responses for increasing scale (scale signature)
K. Grauman, B. Leibe
f ( I i1im ( x, )) f ( I i1im ( x, ))
101
Example
Function responses for increasing scale (scale signature)
K. Grauman, B. Leibe
f ( I i1im ( x, )) f ( I i1im ( x, ))
102
51
4/25/2023
103
DoG G ( x, y, k ) G ( x, y, )
(Difference of Gaussians)
where Gaussian
x2 y 2
G ( x, y , ) 1
2
e 2 2
Note: both kernels are invariant
to scale and rotation
104
52
4/25/2023
105
Characteristic scale
• We define the characteristic scale as the scale
that produces peak of Laplacian response
characteristic scale
T. Lindeberg (1998). "Feature detection with automatic scale selection." IJCV 30 (2): pp 77--116.
Source: Lana Lazebnik
106
53
4/25/2023
Laplacian-of-Gaussian (LoG)
• Interest points: 5
Lxx ( ) L yy ( ) 3
2
List of
(x, y, σ)
107
54
4/25/2023
55
4/25/2023
Alternative approach
Approximate LoG with Difference-of-Gaussian (DoG).
Ruye Wang
111
Alternative approach
• Approximate LoG with Difference-of-Gaussian (DoG):
‒ 1. Blur image with σ Gaussian kernel
‒ 2. Blur image with kσ Gaussian kernel
‒ 3. Subtract 2. from 1.
Small k gives a closer approximation to LoG, but usually we want to build a
scale space quickly out of this. k = 1.6 gives an appropriate scale space, k =
sqrt(2)
- =
56
4/25/2023
…
k 2k
- =
- k List of
= (x, y, s)
- =
Input image
113
Harris-Laplacian
• Harris-Laplacian1 scale
Laplacian
1 K.Mikolajczyk, C.Schmid. “Indexing Based on Scale Invariant Interest Points”. ICCV 2001
2 D.Lowe. “Distinctive Image Features from Scale-Invariant Keypoints”. IJCV 2004
114
57
4/25/2023
115
Laplacian
Find local maximum of:
‒ Harris corner detector in space y
(image coordinates)
Harris x
‒ Laplacian in scale
DoG
Find local maximum of:
Difference of Gaussians in space y
and scale
DoG x
1 K.Mikolajczyk, C.Schmid. “Indexing Based on Scale Invariant Interest Points”. ICCV 2001
2 D.Lowe. “Distinctive Image Features from Scale-Invariant Keypoints”. IJCV 2004
116
58
4/25/2023
G k 2 * I
G k * I
D Gk G * I
G * I
117
D k 2
Dk
D
118
59
4/25/2023
• Orientation assignment
‒ Create histogram of local
gradient directions at selected
scale
‒ Assign canonical orientation at
peak of smoothed histogram
• Each key specifies stable 2D
coordinates
(x, y, scale,orientation)
If 2 major orientations, use both.
119
120
60
4/25/2023
K.Mikolajczyk, C.Schmid. “Indexing Based on Scale Invariant Interest Points”. ICCV 2001
61
4/25/2023
• Others…
123
Feature extraction
• Global features
• Local features
• Interest point detector
• Local descriptor
• Matching
124
62
4/25/2023
Local Descriptor
• Compact, good representation for local information
• Invariant
‒ Geometric transformations: rotation, translation, scaling,..
‒ Camera view change
‒ Illiminution
• Exemples
‒ SIFT, SURF(Speeded Up Robust Features), PCA-SIFT, …
‒ LBP, BRISK, MSER and FREAK, …
125
Following slides credit: CVPR 2003 Tutorial on Recognition and Matching Based on Local Invariant Features David Lowe
126
63
4/25/2023
128
64
4/25/2023
129
130
0 2
• Using precise gradient locations is fragile. We’d like to allow some “slop” in
the image, and still produce a very similar descriptor
• Using Gaussian filter : to avoid sudden changes in the descriptor with small
changes in the position of the window, and to give less emphasis to
gradients that are far from the center of the descriptor, as these are most
affected by misregistration errors
• Create array of orientation histograms (a 4x4 array is shown)
65
4/25/2023
131
0 2
• The SIFT authors found that best results were with 8 orientation bins per histogram
and and a 4x4 histogram array a SIFT descriptor: vector of 128 values
132
66
4/25/2023
SIFT
• Extraordinarily robust matching technique
‒ Can handle changes in viewpoint: up to about 60 degree out of plane rotation
‒ Can handle significant changes in illumination
• Sometimes even day vs. night (below)
‒ Fast and efficient—can run in real time
Steve Seitz
Steve Seitz
133
134
67
4/25/2023
David G. Lowe, "Distinctive image features from scale-invariant keypoints," IJCV, 60, 2 (2004), pp. 91-110
135
136
Feature stability to affine change
68
4/25/2023
137
Distinctiveness of features
69
4/25/2023
139
Feature extraction
• Global features
• Local features
• Interest point detector
• Local descriptor
• Matching
140
70
4/25/2023
Feature matching
Given a feature in I1, how to find the best match in I2?
1. Define distance function that compares two descriptors
• Use L1, L2, cosine, Mahalanobis,… distance
2. Test all the features in I2, find the one with min distance
OpenCV:
- Brute force matching
- Flann Matching: Fast Library for Approximate Nearest Neighbors
[Muja and Lowe, 2009]
Marius Muja and David G Lowe. Fast approximate nearest neighbors with automatic algorithm configuration. In VISAPP (1),
pages 331–340, 2009
141
Feature matching
• How to define the difference between two features f1, f2?
‒ Simple approach: use only distance value d(f1, f2)
• can give good score to very ambiguous matches
71
4/25/2023
Feature matching
• Simple approach: use distance value d(f1, f2)
can give good score to very ambiguous matches
f1 f2
I1 I2
Feature matching
• Better approaches: radio of distance = d(f1,f2) / d(f1,f2')
‒ f2 is best match to f1 in I2;
‒ f2’ is 2nd best SSD match to f1 in I2
‒ An ambiguous/bad match will have ratio close 1
‒ Look for unique matches which have low ratio
f1 f2' f2
I1 I2
72
4/25/2023
145
Ratio of distances reliable for matching
David G. Lowe, "Distinctive image features from scale-invariant keypoints," IJCV, 60, 2 (2004), pp. 91-110
Feature matching
• Better approaches: Spatial constraints between neigborhood pixels
73
4/25/2023
Feature matching
• Better approaches: fitting the transformation (RANSAC alg.)
‒ Fitting 2D transformation matrix
• Six variables
– Each point give two equations
– at least three points
• Least squares
50
75
200
148
74
4/25/2023
149
True/false positives
50
true match
75
200
false match
feature distance
Image matching
• How to define the distance between 2 images I1, I2?
‒ Using global features: easy
d(I1, I2) = d(feature of I1, feature of I2)
150
75
4/25/2023
Voting strategy
Input image Images in a database
Selected region
for query The similarity between 2
images is based on the
number of matches
151
Optimization problem
• Transportation problem
f ij 0
fi
ij w j , f ij wi
j
f d (r , r '
*
)
f ij min( wi , w j )
d EMD (I , I ) i j
ij i j
f
i j i j 1 2 *
ij
i j
http://vellum.cz/~mikc/oss-projects/CarRecognition/doc/dp/node29.html
152
76
4/25/2023
Bag-of-words
• Local feature ~~ a word
• An image ~~ a document
• Apply a technique for textual document representation:
vector model
153
Visual Vocabulary …
154
77
4/25/2023
155
Applications
156
78
4/25/2023
Lowe 2002
Rothganger et al. 2003
Object detection/recognition
158
79
4/25/2023
• Procedure:
‒ Detect feature points in both images
‒ Find corresponding pairs
‒ Use these pairs to align the images
17-Oct-
160
17
80
4/25/2023
Automatic mosaicing
http://www.cs.ubc.ca/~mbrown/autostitch/autostitch.html
161
162
81
4/25/2023
163
Source. http://www-rocq.inria.fr/imedia
164
82
4/25/2023
5 ảnh/nhóm
~80 ảnh/nhóm
~60 ảnh/nhóm
CSDL mô tả đặc
trưng ảnh SIFT
dưới dạng các
Source :ĐATN – Phạm Xuân Trường K52 - BK vector trọng số
Tập ảnh test
165
83
4/25/2023
is.hust.edu.vn 167
References
• Lecture 5,6: CS231 - Juan Carlos Niebles and Ranjay Krishna,
Stanford Vision and Learning Lab
• Vision par Ordinateur, Alain Boucher, IFI
168
84
4/25/2023
169
85