For all p,q such that
,
there exists an r
different from p and q such that
distM(p,q)=distM(p,r)+distM(r,q).
This property is true for the city-block (
),
chess-board (
) and chamfer
(
) metrics - among others - but not for the
Euclidean one when pixels p,q,r are restricted to locations on
an integer grid.
Chamfer DTs were developed and studied by Rosenfeld and Pfaltz [132,133], Montanari [109], Barrow [3], Borgefors [10,12], Piper and Granum [122], Forchhammer [56], Verwer, Verbeek and Dekker [167], Sharaiha and Christofides [145] and Coquin and Bolon [22].
Rosenfeld [132,133] proposes raster
scanning (see below) and independent scanning (see section
) algorithms for the distance transformation
using the dist4 and dist8 metrics. Montanari
[109] investigates distances defined as the length of
the shortest path between two pixels. If the path is restricted to
steps between 4-direct neighbors, this is equivalent to the
dist4 metric. With 8-direct neighborhoods, it defines a
metric. Montanari proves that the
shortest path between two points consists of at most two types of
steps, those with orientations closest to the Euclidean vector
between those points. This property is central to the later
publications by Borgefors [10] and Ragnelmam
[127]. Barrow [3] uses a DT similar
to Montanari's, replacing
by (2:3), an integer
approximation.
In [10], Borgefors reviews a number of metrics
in 2 and 3 dimensions. Chamfer distance transformations are
produced in two raster scans over the image, using the masks of
Figure
. In the forward scan, the mask
starts in the upper left corner of the picture, moves from left to
right and from top to bottom. In the backward scan, it starts in
the lower right corner, moves from right to left and from bottom
to top. The local distances, d1 and d2, in the mask pixels
are added to the pixel values in the distance map and the new
value of the zero pixel is the minimum of the five sums.
This algorithm can produce distance transformation with several
metrics. For instance, for d1=1 and
,
we have the
city block metric; for d1=d2=1, the chess board metric, for
d1=1 and
,
Montanari's metric and for d1=2 and
d2=3, Barrow's approximation. Borgefors computes the optimal
values for d1 and d2 in order to minimize the maximal
difference between the chamfer metric and the Euclidean one.
Assuming that
(otherwise the diagonal direction
is never used), the distance between two pixels is
)). The difference
between the Euclidean and chamfer distance is thus
). The
maximum occurs either for m2 = 0, m2 = m1 or the value of
m2 where the differential is 0. For m2 = 0,
(
) is zero. For m2 = m1,
(
) becomes
) with
respect to m2 is zero for
), we find
and
happens when they
cross each other at
.
The upper limit for (
) is then
.
Slightly
better results could actually be obtained by removing the
constraint that d1=1, as in [166], but this is beyond
the scope of the present review.
For computational efficiency, floating point operations are not
desirable, and therefore Borgefors suggests to use the
sub-optimal integer approximation d1=3 and d2=4, then to
divide the resulting DT by 3. In this case, the upper limit for
the difference between the Euclidean and chamfer metric becomes
.
This is obviously much better than
the limits found for the city-block and chess-board metrics,
and
,
respectively.
In 3 dimensions, the optimal values are d1=1,
and
,
which gives
for the
upper limit of the absolute difference between the metrics. Once
again, it is often better to consider a sub-optimal integer
approximation with d1=3, d2=4 and d3=5. The upper limit
of the difference with the Euclidean metric is then
.
In [12], Borgefors extends the chamfer masks
to
and
.
She computes the optimal values
for the local distances and evaluates several integer
approximations for
to
masks. She
recommends using (3:4) and (5:7:11) approximations for
and
masks, but finds no significant interest in
using
masks. The gain in precision becomes negligible
compared to the additional cost of using larger masks. With
chamfer (5:7:11), the upper limit for the absolute difference
between this metric and the Euclidean one is reduced to 0.02 M.
The chamfer (5:7:11) DT is illustrated at Figure
.
![]() |
Piper and Granum [122] and Verwer et al.
[167] propose to reach the same results with a different
type of scanning. Instead of two raster scans, they use a
propagation from the object pixels to the rest of the image. This
proves to be more efficient on non-convex image domains, and will
be further explained in section
.
Sharaiha and Christofides [145] propose a graph theoretic approach to chamfer distance transformation. They represent the image as a graph where pixels are represented as vertices and adjacency relations as arcs. The cost associated with each arc is equal to the equivalent local distance in the chamfer masks. The vertices associated to the object pixels are called root vertices. The Chamfer DT problem is then equivalent to the shortest path forest problem in graph theory. They solve this using a variation of the algorithms proposed by Moore [110] and Dial [39]. Practically, this is similar to Piper's approach [122], with a more complex data representation.
In [56], Forchhammer shows that, within a
limited distance, the true Euclidean distance can be deduced from
its chamfer approximation. In particular, using the
mask with (3:4) local distances, the exact EDT can be deduced from
the chamfer distances for
,
but not beyond.
Finally, Bolon [9] and Coquin [22]
extend the chamfer metrics to anisotropic grids. The optimal mask
coefficients are found by minimizing the maximum of the difference
between the anisotropic chamfer metric and the Euclidean along a
circle. The complete solution is given for
anisotropic masks, but can be applied to other masks as well.