Professional Documents
Culture Documents
CHAPTER 4
4. METHODS FOR MEASURING DISTANCE IN IMAGES
4.1. INTRODUCTION
In image analysis, the distance transform measures the distance of each object point
from the nearest boundary and is an important tool in computer vision, image processing and
pattern recognition. In the distance transform, binary image specifies the distance from each
pixel to the nearest non-zero pixel. The euclidean distance is the straight-line distance
between two pixels and is evaluated using the euclidean norm. The city block distance metric
measures the path between the pixels based on a four connected neighbourhood and pixels
whose edges touch are one unit apart and pixels diagonally touching are two units apart.
The chessboard distance metric measures the path between the pixels based on an
eight connected neighbourhood. The quasi-euclidean metric measures are the total euclidean
distance along a set of horizontal, vertical, and diagonal line segments. A central problem in
image recognition and computer vision is determining the distance between images and
efforts which have been made to define image distances to provide intuitively reasonable
results. Estimating distances in digital image is useful in different shape representation and
shape recognition tasks [Borgefors 1994].
51
Description
Illustration
0 0 0
0 1 0
1.0
0 0 0
Image
Distance Transform
pixels.
City Block
0.0
1.0
1 0 0
0 1 0
0 0 0
Distance
Transform
Image
1 0 0
0 1 0
0 0 0
Quasi-
The
quasi-Euclidean
Euclidean
measures
Image
metric
0 0 0 0 0
0 0 0 0 0
0 0 1 0 0
2.0 1.0
0 0 0 0 0
0 0 0 0 0
the
total
Euclidean
Image
Chamfer
distance
Distance
Transform
c2 c1 c2
c1 0 c1
c2 c1 c2
1.0 2.0
Distance Transform
c2 c1 c2
c1 0
0 c1
c2 c1 c2
starting from A to B
52
,
by
, |
|
1
1 2
2 n
n
i
i
In one dimension, the distance between two points, x1 and x2, on a line is simply the
absolute value of the difference between the two points as:
53
2
1 |2
1 |
In two dimensions, the distance between P = (p1, p2) and q = (q1, q2) as:
1
1 2
2
Step1: load the column vector x;
Step2: load the code book;
Step3: minimum distance is initially set to the first element of cb.
Step4: i.e. set idx=1;
Step5: compute distance by normalized values of (x-cb) for all cb;
Step6: if d is less than distance set distance is equal to d;
Step7: set idx=index;
Step8: end
Figure 4.1 Euclidean distance algorithm
54
The euclidean distance is calculated from the center of the source cells to the center of
each of the surrounding cells and true distance is calculated to each cell in the distance
functions. The euclidean algorithm works as follows: for each cell, the distance is calculated
to each source cell by calculating the hypotenuse, with the x-max and y-max. Figure 4.3
shows sample sonographic image of appendicitis.
55
location (k, l). Thus an image x = (x1, x2 ,., xMN ) , where xkN+l is the gray level at the
(k, l)th pixel, is represented as a point in the image space, and xkN+l with respect to ekN+ l . The
origin of the image space is an image whose gray levels are zero everywhere
[Liwei Wang et al., 2005].
Although the algebra of the image space can be easily formulated as above, the
euclidean distance of images could not be determined until the metric coefficients of the basis
are given. The metric coefficients gij i, j =1, 2,..,MN , are defined as
where <, > is the scalar product, and ij is the angle between ei and ej . Note that, if
< ei ei > = < ej ej> =, i.e. all the base vectors have the same length, then gij depends
56
completely on the angle ij. Given the metric coefficients, the euclidean distance of two
images x, y is written by
Geometrically, this defect is due to the orthogonality of the base vectors e1, e2
,..,eMN which correspond to pixels. Clearly, the information about the spatial relationship,
i.e. the distances between the pixels, cannot be reflected by all mutually perpendicular base
vectors. Such information, however, often appears in intuitive image distance as in the
following statement: A slightly deformed image is very similar to the original one. Here,
slightly deformed means that pixels in the deformed image are close to the corresponding
pixels in the original image. This implies that a good euclidean distance for images should
contain the information of pixel distances. Accordingly, the metric coefficients, which define
the euclidean distance, have to be related to the pixel distances.
57
If the metric coefficients depend properly on the pixel distances, the obtained
euclidean distance is insensitive to small deformation. The two distances that are considered
are: one is the image distance measured in the high dimensional image space, the other is the
pixel distance. Let PiPj , i, j = 1, 2,.., MN , be pixels. The pixel distance, written as
| Pi Pj |, is the distance between Pi and Pj on the image lattice. For example, if Pi is at
location (k, l), and Pj is at (k, l) , | Pi Pj | may be
. Let euclidean
58
image I and a binary edge map E of the image I, the basic form of chamfer distance is
calculated as
where || . ||2 is l2 norm and |T| denotes number of points in template T. Chamfer
distance can be efficiently computed as:
Chamfer distances are used for computing geodesic diameters to propagate chamfer
distances from a binary image, constrained to another binary image.
59
Chamfer distance algorithms are a class of discrete algorithms that offer a good
approximation and euclidean distance transform at a lower computational cost. The distance
approximates the global distance computation with repeated propagation of local distances
within a small neighborhood mask. The approximation error depends upon the size of the
neighborhood and the selection of the local distances [Muhammad Akmal et al., 1998].
Figure 4.5 shows the sample chamfer distance.
Chamfer distances are local distances which permit to deduce a distance from the
distances of close neighbours unlike dE. The computation of the medial axis is done by a local
test and all computations are done by using integer numbers and linear operations such as +, and <. Figure 4.6 shows euclidean and chamfer distances on appendicitis image.
60
Figure 4.7 Euclidean and geodesic distances on a circle [Balu et al., 2012]
61
Geodesic has shortest paths, and perturbation of a geodesic curve will increase its
length. A geodesic distance between two vertices of a triangle mesh surface can be computed
using a shortest path algorithm on the mesh graph with an edge is its length. The Dijkstras
algorithm can lengths of paths very quickly, but produce paths quite different from true
geodesics and the paths created pass only through the mesh vertices. The research on
geodesic computation on a surface focuses on solving the eikonal equation. Kimmel and
Sethian proposed an optimal time algorithm for computing the geodesic distances and
extracting shortest paths on triangulated manifolds using the fast marching method
[Sifri et al., 2003].
62
assumed to be continuous. Given a binary mask M (with M(x) {0, 1}, x ) associated
distance transform D0 (. ; M, I) assigns to each pixel x its geodesic distance from defined
as :
Where Pa,b is the set of all possible differentiable paths in between the points a and
b and (s) : R R2 indicates a path, parametrized by its arc length s [0, l()]. The spatial
derivative ` (s) = (s) / s is the unit vector tangent to the direction of the path. The dot-
product is ensuring the maximum influence for the gradient I when it is parallel to the
direction of the path . The geodesic factor weighs the contribution of the image gradient
versus the spatial distances. Figure 4.9 shows the difference between euclidean distance and
geodesic distance.
63
------------------------------------------------ (1)
Instead of two dimensions, if the points have n-dimensions, such as a = (x1 , x2 ,..., xn)
and b = (y1 , y2 ,..., yn) then, equation (1) can be generalized by defining the manhattan
distance between a and b as
64
Figure 4.10 shows euclidean and manhattan distances on an appendicitis image. The
yellow lines are representing euclidean and green lines are representing manhattan distance.
The Manhattan distance function computes the distance that would be travelled from one data
point to the other if a grid-like path is followed and manhattan distance between two items is
the sum of the differences of their corresponding components.
|
|
65
The city block distance transform is a basic operation in computer vision, pattern
recognition and robotics. For instance, if the black pixels represent obstacles, then dij tells us
how far the point (i, j) is from these obstacles. This information is useful when one tries to
move a robot in the free space hit pixels of the image and to keep it away from the obstacles.
Many algorithms have been proposed for computing the distance transform using different
distance metrics. Figure 4.12 shows difference between euclidean distance and city block
distance.
Figure 4.12 Euclidean distance vs city block distance [Sarah et al., 1999]
66
Figure 4.13 Euclidean Distance vs Chess Board Distance [Sarah et al., 1999]
Figure 4.14 Euclidean Distance vs Chess Board Distance Matrix [Antoni Moore, 2002]
67
4.9. SUMMARY
The relationship and understanding among different distance measures is helpful in
choosing a proper measure for a particular application. Various distance measures, euclidean
distance, chamfer, geodesic, manhattan, city block and chess board distance are described in
detail. This chapter highlighted euclidean distance, how it is useful and described chamfer
distance as available from literature. In addition, this chapter illustrated the difference
between geodesic and euclidean distance and also demonstrated differences between
manhattan and euclidean distance, euclidean and city block distance.