You are on page 1of 75

17.

- Minimum-Distance Classification

Image Processing - Pattern Recognition


Prof. Dr.-Ing. Norbert Diehl

Minimum-Distance Classification
and
Template Matching

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.1


17. - Minimum-Distance Classification

Notes on the lecture materials


 These documents are for personal use only in addition to the lecture and
may not be passed on and may not be reused.

 No guarantee is given that the documents are free of errors.

 The graphics and pictures contained in the documents are partly taken from the
the books mentioned in the bibliography or the accompanying documents
provided by the publisher or author. Thank you very much for this.

 It is expressly pointed out that contents may be deepened, supplemented or


omitted from the lecture.

 Thus, these slides neither replace attending the lecture nor studying
suitable books or essays.

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.2


17. - Minimum-Distance Classification

Contents of the Lecture


 ...
11. Morphological Image Processing - Basics: Dilation and Erosion
 12. Morphological Image Processing - Filters: Opening and Closing
 13. Gray-Scale Morphology
 14. Segmentation - Thresholding
 15. Properties of Binary Regions
 16. Texture-based Region Properties
 17. Minimum Distance Classification
 18. Bayes and Nearest Neighbor Classification
 19. Neural Networks
 20. Convolutional Neural Networks

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.3


17. - Minimum-Distance Classification

Literature - Text Books


 Gonzalez, Rafael C.; Woods, Richard E.: Digital Image Processing;
Pearson, 4th Global Edition
Chapter 12: Image Pattern Classification
12.1 Background
12.2 Pattern and Pattern Classes
12.3 Pattern Classification by Prototype Matching

Burger, Wilhelm; Burge, Mark J.: Digital Image Processing:


An Algorithmic Introduction Using Java; Springer, 2nd edition
Chapter 23: Image Matching and Registration
23.1 Template Matching in Intensity Images

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.4


17.1. - Pattern Recognition and Classification

Image Processing - Pattern Recognition

Minimum-Distance Classification

1. Pattern Recognition and Classification

2. Pattern Recognition Systems

3. Decision-theoretic Methods

4. Minimum-Distance Classifier

5. Template Matching

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.5


17.1. - Pattern Recognition and Classification

Pattern Recognition and Classification


Pattern recognition refers to
- automatically assigning measured signals / objects to categories, i.e.
- automatically classifying them with respect to some features.

Model

Features Classifier Classes


Images (classification rule) (group of objects
(patterns with specidic
with similar fatures)
properties. e.g.texture)

Automation and human intervention


- task specification: what classes, what features
- algorithm used for classification
- training: tuning algorithm parameters
N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.6
17.1. - Pattern Recognition and Classification

Pattern Recognition - Example


• Classifying nuts

Features Pine-nuts (Pinienkerne)


Classifier
(circularity, Lentils (Linsen)
(classification rules)
line-fit-error) Pumpkin seeds (Kürbiskerne)

pine-nut

lentil

pumpkin seed
N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.7
17.1. - Pattern Recognition and Classification

Pattern Recognition - Example


Classify different kinds of iris flowers (Schwertlilien) based on the
geometric properties of their blossoms (Blüte).

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.8


17.1. - Pattern Recognition and Classification

Features
Features describe the patterns (objects) to be classified based
on specific, distinctive properties (parameters).
Features may be numeric (height, texture, ...) or symbolic values (color, ...)

Definitions
- The combination of n features is a n-dim vector called a feature vector
- Objects are represented as points in the feature space -> scatter plots
- Objects with same or similar features are grouped into classes w1, w2, ...

Classes
w1, w2, w3

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.9


17.1. - Pattern Recognition and Classification

Pattern Classes
Patterns are described using feature vectors

The feature vectors represent points in the n-dimensional feature space.

A pattern class w can be interpreted as a “hypercloud” of points


in this feature space, which are close to each other and thus
have similar feature values.

For the purpose of recognition,


we like for our pattern classes
to be grouped tightly, and
as far away from each other
as possible.

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.10


17.1. - Pattern Recognition and Classification

Feature Selection
The quality of a feature vector is related to its ability to clearly
identify / discriminate different pattern classes.
- Patterns from the same class should have similar feature values
- Patterns from different classes should have different feature values

More feature properties

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.11


17.1. - Pattern Recognition and Classification

Feature Vectors
Pattern vectors are normally based on image features such as
- binary region properties
- boundary shape properties
- texture and region properties

Geometry
(Blütenblatt)
based
features
(Kelchblatt)

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.12


17.1. - Pattern Recognition and Classification

Feature Vectores

Binary region
properties
based features

Moment
invariants
as features

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.13


17.1. - Pattern Recognition and Classification

Feature Vectores

Texture
based
features

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.14


17.1. - Pattern Recognition and Classification

Feature Vectores

Signatures - geometry based features


(distance from center)

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.15


17.1. - Pattern Recognition and Classification

Classifiers
The task of a classifier is to partition the feature space into
class-labeled decision regions 1, 2, 3, ..., W, called classes w1, w2, ...
- Borders between decision regions are called decision boundaries.
- The classification of a feature vector 𝑥 consists of determining
which decision region (class) it belongs to, and assign 𝑥 to this class.

w1 w1
w2

w3

w3 w2
w4

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.16


17.1. - Pattern Recognition and Classification

Classifiers
A classifier can be represented as a set of
discriminant (decision) functions di(x) for the classes wi.
- The classifier assigns a feature vector 𝑥 to class wi if

- Based on the discriminant


(decision) functions di(x)
the classifier determines
decision boundaries dij(x)
to separate the classes.

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.17


17.1. - Pattern Recognition and Classification

Pattern Recognition - Example


Classify different kinds of iris flowers (Schwertlilie) based on the
geometric properties of their blossoms (Blüten).

Iris flower dataset


- 50 samples from each for the three species of iris flowers.
- 4 features were measured from each sample:
the length and the width of the sepals (Kelchblatt) and petals (Blütenblatt)

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.18


17.1. - Pattern Recognition and Classification

Pattern Recognition - Example


Features

petal

sepal

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.19


17.1. - Pattern Recognition and Classification

Pattern Recognition - Example

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.20


17.1. - Pattern Recognition and Classification

Scatterplots
two classes

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.21


17.2. - Pattern Recognition Systems

Image Processing - Pattern Recognition

Minimum-Distance Classification

1. Pattern Recognition and Classification

2. Pattern Recognition Systems

3. Decision-theoretic Methods

4. Minimum-Distance Classifier

5. Template Matching

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.22


17.2. - Pattern Recognition Systems

Pattern Recognition Systems

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.23


17.2. - Pattern Recognition Systems

Pattern Recognition Systems

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.24


17.2. - Pattern Recognition Systems

Pattern Recognition Systems

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.25


17.2. - Pattern Recognition Systems

Supervised and Unsupervised Learning

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.26


17.3. - Decision-theoretic Methods

Image Processing

Minimum-Distance Classification

1. Pattern Recognition and Classification

2. Pattern Recognition Systems

3. Decision-theoretic Methods

4. Minimum-Distance Classifier

5. Template Matching

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.27


17.3. - Decision-theoretic Methods

Classification Methods - Overview


Goal of pattern recognition: Assign patterns to their classes
with as little human interaction as possible
Matching (prototype matching)
- An unknown pattern is assigned to the class to which it is closest
with respect to a metric
- Minimum-Distance Classifier
The Euclidean distance is used as metric between the unknown pattern
and prototype vectors representing the classes - discussed in this chapter
- Correlation (template matching)

Statistical classifiers - Bayes Classifiers - discussed in the next chapter

Neural networks - discussed in later chapters

All methods are based on decision functions -> Decision-theoretic Methods


N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.28
17.3. - Decision-theoretic Methods

Decision Functions
Decision-theoretic methods are based on decision (discriminant)
functions.

Let represent a feature vector describing a pattern.

For W pattern classes w1, w2, ..., wW the basic problem is


to find W decision (discriminant) functions

with the property that if x belongs to wi

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.29


17.3. - Decision-theoretic Methods

Decision Boundaries
The classes can be separated using decision boundaries dij(x)
based on the decision functions di(x) and dj(x)

The decision boundary dij(x) separating class wi from class wj


is given by the values of x for which the decision functions

or dij(x)

If x belongs to class wi we have

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.30


17.3. - Decision-theoretic Methods

Decision Boundaries
The decision boundary separating
class wi from class wj is given

For two classes wi and wj we have

Important Question:
How should we choose
the decision function and
the decision boundaries?
N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.31
17.3. - Decision-theoretic Methods

Decision Boundaries

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.32


17.4. - Minimum-Distance Classifier

Image Processing - Pattern Recognition

Minimum-Distance Classification

1. Pattern Recognition and Classification

2. Pattern Recognition Systems

3. Decision-theoretic Methods

4. Minimum-Distance Classifier

5. Template Matching

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.33


17.4. - Minimum-Distance Classifier

Prototype Matching
Classification based on matching involves
- comparing an unknown (actual) pattern against a set of prototypes
characterizing the different classes,
- assigning the unknown pattern to the class of the prototype
that is the most “similar” to the unknown.

Each prototype represents a unique pattern class.

What distinguishes one matching method from another


is the measure used to determine similarity.

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.34


17.4. - Minimum-Distance Classifier

Minimum-Distance Classifier
Minimum-Distance Classifier
- one of the simplest and most widely used prototype matching methods
- computes a distance-based measure between the feature vector
of an unknown pattern x and each of the class prototype vectors mj.
- assigns the unknown pattern to the class with the minimum distance
between feature vector and class prototype.
m1
distance for class j
m2
=W

feature prototype mW
vector of class j
how to find the prototyps: discussed later
N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.35
17.4. - Minimum-Distance Classifier

Minimum-Distance Classifier
A distance (decision) measure determines the similarity.
That is, the smallest distance implies the best match.

Often we use the Euclidean distance

=W

with the Euclidean norm resp.

The classifier then assigns an


m1
unknown pattern x to class ci if
m2
minimize

W mW

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.36


17.4. - Minimum-Distance Classifier

Decision Functions
Selecting the smallest distance is equivalent to evaluating the
decision or discriminant functions.

and assigning an unknown pattern x to the class whose prototype


yielded the largest value of dj(x).

That is, x is assigned to class ci with

W maximize

i.e. the largest dj(x).

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.37


17.4. - Minimum-Distance Classifier

Decision Boundaries
The decision boundary dij(x) separating class ci from cj is given by
the values of x for which the decision functions

dij(x)
have the same value or, equivalently,
by values of x for which

The decision boundaries for a minimum-distance classifier is given by

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.38


17.4. - Minimum-Distance Classifier

Decision Boundaries

This boundary is the perpendicular bisector of the line joining mi and mj.

In the 2-dimensional case (i.e. W=2), the perpendicular bisector is a line,


for W=3 it is a plane, and for W>3 it is called a hyperplane.

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.39


17.4. - Minimum-Distance Classifier

Prototypes and Classes


How to define the prototypes mj for the different classes cj

- They may be well defined and known in advance;


e.g. optical inspection: correct, defect-free reference part or component

- They may be not exactly known in advance, but estimated


based on a training (sample) data set.
Often the means of feature vectors x of samples of the
various pattern classes cj are used.

Nj is the number of pattern vectors used to compute the j-th mean vector

cj is the j-th pattern class, and W is the number of classes.


N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.40
17.4. - Minimum-Distance Classifier

Prototypes and Classes


If the prototypes of the
classes are not well known
or if they are not predefined,
they have to be learned
(estimated) by a set of
training data.

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.41


17.4. - Minimum-Distance Classifier

Minimum-Distance Classifier - Example


We denote the iris versicolor and iris setosa data as classes c1 and c2,
respectively. The means of the two classes are

linear discrimiants
linear classifier

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.42


17.4. - Minimum-Distance Classifier

Example with Texture Features


0.86
0.81 Uniformity 1.00
The texture 1.00
0.91 Contrast 0.89
5.20
5.25 Entropy 5.12
measures of 0.84
0.87 1.00
1.00
the different 0.91 0.89
5.19
5.16 5.09
regions 0.05
0.16
clearly differ. 0.02 7.97
0.32 0.24
8.91 0.04
0.10
0.16
Sky, buildings 0.02 8.37
7.01
0.34 0.19
and water 8.98 0.10
can be 7.38
0.19
discriminated 0.24 0.30 0.21
0.62 0.56 6.58 0.14
based on 6.43 0.32
6.25 0.07 6.85
these features. 0.14 0.18 0.21
0.62 0.56 745 0.08
6.97 0.32
6.75 feature vector
7.39
to be classified

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.43


17.4. - Minimum-Distance Classifier

Example with Texture Features - Prototypes


1.00 0.86
0.89 1.00
0.81 5.12 5.20
0.89 0.10 0.23 0.91 1.00 0.84
0.93 0.19 0.50 5.25 0.89 1.00
5.19 7.96 6.51 0.87 5.09 5.19
0.90 0.08 0.13 0.91
0.93 0.20 0.50 5.16
5.15 8.24 7.04 0.05
0.16
0.02 7.97
prototype vectors 0.32 0.04 0.24
8.91 0.16 0.10
0.02 8.37 7.01
0.34
0.19
8.98
0.10
7.38

three 0.19
0.24
0.30 0.21 0.14
classes: 0.62
6.58
6.43 0.56 0.32
0.07
sky, 0.14 6.25
0.21
6.85
0.62 0.18 0.08
buildings. 0.56 7.45 0.32
6.97
6.75 feature vector 7.39
water to be classified

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.44


17.4. - Minimum-Distance Classifier

Example with Texture Features - Classification


prototype vectors
0.89 0.10 0.23
0.93 0.19 0.50
5.19 7.96 6.51
0.90 0.08 0.13
0.93 0.20 0.50
5.15 8.24 7.04

3.07 1.59 0.59

0.19
0.21
6.58
0.07 0.19
0.21
7.45 ? 0.21
6.58
0.07
classification 0.21
7.45
of an unknown
feature vector
region to be classified

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.45


17.4. - Minimum-Distance Classifier

American Bankers Association Font E-13B


scan
The font was designed to be compact
and readable quickly by machines.
14 characters laid out on a 9 × 7 grid.
The characters are stylized to
maximize the difference when scanned
horizontally by a head
narrower but taller than the characters.
This produces a 1-D signal proportional
to the rate of change of the area (ink)
under the character.
The waveforms (signatures) are
different for each character.
N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.46
17.4. - Minimum-Distance Classifier

American Bankers Association Font E-13B


The design of the font ensures that
- the waveform of each character is distinct from all others,
- the peaks and zeros of each waveform occur approximately
on the vertical lines of the background grid,
- sampling the waveforms only at these (nine) points yields enough
information for their accurate classification

Minimum-Distance Classifier
- store the sample values of each waveform at the vertical lines
- let each set of the resulting samples be represented as a 9-dim
prototype vector mj , j = 1, 2,…, 14.

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.47


17.4. - Minimum-Distance Classifier

American Bankers Association Font E-13B


Classifying an unknown character
- scan it in the manner just described,
- express the grid samples of the waveform as a 9-dim vector x,
- identify its class by selecting the class of the prototype vector
that yields the highest value of

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.48


17.4. - Minimum-Distance Classifier

Minimum-Distance Classifier
One of the keys to accurate recognition performance is to specify
features that are effective discriminators between classes.

- the better the features are at meeting this objective,


- the better the recognition performance will be.

For the case of the minimum-distance classifier this implies


- wide separation between means of the prototypes and
- tight grouping of the classes.

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.49


17.4. - Minimum-Distance Classifier

Distance Functions - Metrics

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.50


17.4. - Minimum-Distance Classifier

Distance Functions - Metrics

Mehalanobis distance - -

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.51


17.4. - Minimum-Distance Classifier

Distance Functions - Metrics


Euclidean Distance

Mehalanobis Distance

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.52


17.4. - Minimum-Distance Classifier

Feature Normalization

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.53


17.4. - Minimum-Distance Classifier

Feature Normalization

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.54


17.4. - Minimum-Distance Classifier

Feature Normalization

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.55


17.4. - Minimum-Distance Classifier

Feature Normalization

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.56


17.4. - Minimum-Distance Classifier

Feature Normalization

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.57


17.5. - Template Matching

Image Processing - Pattern Recognition

Minimum-Distance Classification

1. Pattern Recognition and Classification

2. Pattern Recognition Systems

3. Decision-theoretic Methods

4. Minimum-Distance Classifier

5. Template Matching

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.58


17.5. - Template Matching

Template Matching
Special type of Minimum-Distance Classifier
Instead of using special features for classifying
use the whole image or a image region
as the feature, now called template.

template

image metric

Red points correspond the points of best match, i.e. positions of the template within the image
N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.59
17.5. - Template Matching

Template Matching

I = s[x,y] R = t[x,y]

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.60


17.5. - Template Matching

Template Matching

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.61


17.5. - Template Matching

Distance between Image Patterns

template

original image

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.62


17.5. - Template Matching

Distance between Image Patterns

Corresponds to a minimum
distance classifier using the
whole template / reference
image as the feature vector

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.63


17.5. - Template Matching

Matching by Euclidean Distance

minimize with
respect to r and s

often nearly constant constant Correlation

- often nearly constant


Minimimzing the squared difference corresponds to maximizing
the correlation function.
N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.64
17.5. - Template Matching

Matching by Normalized Cross Correlation

maximize with
respect to r and s

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.65


17.5. - Template Matching

Matching by Correlation Coefficient

maximize with
respect to r and s

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.66


17.5. - Template Matching

Matching by Correlation
Detection of the eye of a hurricane

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.67


17.5. - Template Matching

Examples and Discussion

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.68


17.5. - Template Matching

Examples and Discussion

White points correspond the points of best match, i.e. minimum value of the distance function.
N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.69
17.5. - Template Matching

Examples and Discussion

White points mark points of best match, i.e. min. value of the dist. function. or max. of correlation.
N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.70
17.5. - Template Matching

Examples and Discussion

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.71


17.5. - Template Matching

Effects of Changing Intensity

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.72


17.5. - Template Matching

Effects of Rotation and Scaling

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.73


17.5. - Template Matching

Shape of Template

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.74


17. - Minimum-Distance Classification

Image Processing - Pattern Recognition

Minimum-Distance Classification

1. Pattern Recognition and Classification

2. Pattern Recognition Systems

3. Decision-theoretic Methods

4. Minimum-Distance Classifier

5. Template Matching

N. Diehl, V-2022-final IPPR: Minimum Distance Classification 17.75

You might also like