A metric or distance function is a function d(p,q) of two points p and q which satisfies:
Frequently used examples are:
The Euclidean distance: in two dimensions,
In a digital image, the elements of p and q are row and column numbers. Generalized to any number of elements in p and q, one can write
Points with equal File:Hepa img680.gif from p form a circle (sphere, hypersphere) of radius File:Hepa img680.gif around p.
The city block distance: in two dimensions,
with obvious generalization to more dimensions. Points (pixels in an image) with equal File:Hepa img682.gif from p form a diamond around p; in an image:
Points with File:Hepa img684.gif from p are called the 4-connected neighbours of p.
The chess board distance: in two dimensions,
Points with equal File:Hepa img686.gif from p form a square around p; in an image:
Points (pixels in an image) with File:Hepa img688.gif from p are called the 8-connected neighbours of p. e.g. Rosenfeld76.
A metric can also be defined in a binary space, e.g. as the distance between two bit patterns ( Hamming Distance).