Algorithm Search⌘K

Definitioncore

Chamfer distance between point sets

Also called symmetric chamfer distance.

The sum over both point sets of the squared distance from each point to its nearest point in the other set: a common loss and score for point clouds, but not a metric.

The chamfer distance between two finite point sets measures how far each point of one set is from the nearest point of the other, in both directions, and adds it all up. It is cheap to compute with a nearest neighbour search, it needs no correspondence between the points, and it has a gradient almost everywhere. For these reasons it is the standard loss for neural networks that output point clouds, and a common score for how well a reconstruction or a registration fits. This page uses the form of Fan, Su and Guibas (2017): squared distances, summed over the points of both sets. Other papers use means instead of sums, or plain distances instead of squared ones; these forms differ by constant factors or in their sensitivity to far points, and a paper should always say which one it uses. The name comes from chamfer matching in images (Barrow et al., 1977), which is a different, one-sided measure on an image grid.

Definition

Let S1S_1 and S2S_2 be finite, nonempty subsets of Rd\mathbb{R}^d. The chamfer distance is

dCD(S1,S2)=∑x∈S1min⁡y∈S2∥x−y∥22+∑y∈S2min⁡x∈S1∥x−y∥22.d_{\mathrm{CD}}(S_1, S_2) = \sum_{x \in S_1} \min_{y \in S_2} \|x - y\|_2^2 + \sum_{y \in S_2} \min_{x \in S_1} \|x - y\|_2^2 .

Each sum is a one-sided chamfer distance: the first says how well S2S_2 covers the points of S1S_1, and the second how well S1S_1 covers the points of S2S_2.

Other forms in use:

  • Mean form. Divide each sum by the size of its set, 1∣S1∣∑x∈S1⋯+1∣S2∣∑y∈S2⋯\frac{1}{|S_1|} \sum_{x \in S_1} \cdots + \frac{1}{|S_2|} \sum_{y \in S_2} \cdots. Many libraries compute this form, so that the value does not grow with the number of points.
  • Plain distances. Use ∥x−y∥2\|x - y\|_2 instead of its square. A far point then counts less, and the value has the units of a length.
  • One-sided form. Keep only one of the two sums, for example when S2S_2 is a full model and S1S_1 a partial scan of it.

Properties. dCDd_{\mathrm{CD}} is symmetric, it is at least 0, and it is 0 exactly when S1=S2S_1 = S_2: if it is 0, every point of each set lies in the other. It is not a metric, because it breaks the triangle inequality, as the examples show. It ignores how many times a point is repeated, so it does not compare densities.

Cost. By brute force it takes Θ(∣S1∣⋅∣S2∣)\Theta(|S_1| \cdot |S_2|) time. With a k-d tree on each set and n=∣S1∣+∣S2∣n = |S_1| + |S_2|, the nn nearest neighbour queries take O(log⁡n)O(\log n) time each on well spread points in low dimension, so about O(nlog⁡n)O(n \log n) in all.

Examples and non-examples

A small case. In the plane, let S1={(0,0),(2,0)}S_1 = \{(0, 0), (2, 0)\} and S2={(0,1),(3,0),(3,1)}S_2 = \{(0, 1), (3, 0), (3, 1)\}.

Point Set Nearest in the other set Squared distance
(0,0)(0, 0) S1S_1 (0,1)(0, 1) 1
(2,0)(2, 0) S1S_1 (3,0)(3, 0) 1
(0,1)(0, 1) S2S_2 (0,0)(0, 0) 1
(3,0)(3, 0) S2S_2 (2,0)(2, 0) 1
(3,1)(3, 1) S2S_2 (2,0)(2, 0) 2

So dCD=(1+1)+(1+1+2)=6d_{\mathrm{CD}} = (1 + 1) + (1 + 1 + 2) = 6. The mean form gives 2/2+4/3≈2.3332/2 + 4/3 \approx 2.333, and the form with plain distances gives 1+1+1+1+2≈5.4141 + 1 + 1 + 1 + \sqrt{2} \approx 5.414. The Hausdorff distance, the largest of these nearest distances, is 2\sqrt{2}.

The triangle inequality fails. On the line, let S1={0}S_1 = \{0\}, S2={1}S_2 = \{1\} and S3={2}S_3 = \{2\}. Then dCD(S1,S3)=4+4=8d_{\mathrm{CD}}(S_1, S_3) = 4 + 4 = 8, but dCD(S1,S2)+dCD(S2,S3)=2+2=4d_{\mathrm{CD}}(S_1, S_2) + d_{\mathrm{CD}}(S_2, S_3) = 2 + 2 = 4. The squares cause this. The form with plain distances fails too, for another reason: with S1={0}S_1 = \{0\}, S2={0,1}S_2 = \{0, 1\} and S3={1,1.1,1.2}S_3 = \{1, 1.1, 1.2\}, it gives 1+3.3=4.31 + 3.3 = 4.3 from S1S_1 to S3S_3, but only 11 from S1S_1 to S2S_2 plus 1+0.3=1.31 + 0.3 = 1.3 from S2S_2 to S3S_3. Each point of S3S_3 adds its own term, so a set with many points far from a small set gets a large value.

Density is not seen. Let S1S_1 be 100 points spread evenly on a segment, and S2S_2 the same 100 points plus 900 more points packed near one end. Each point of S2S_2 has a near point in S1S_1, and each point of S1S_1 lies in S2S_2, so the chamfer distance is small, although the two sets sample the segment in very different ways. A measure that moves mass from one set to the other, such as the earth mover's distance with equal total weight on each set, sees this difference.

Not the image chamfer distance. The chamfer distance transform of an image gives each pixel an approximate distance to the nearest edge pixel, by two raster passes with small integer weights. Chamfer matching (Barrow et al., 1977) scores an edge template at a pose by the values of such a distance transform under the template points. That score is one-sided, from the template to the image, and it lives on a pixel grid. The point set chamfer distance is two-sided and uses exact Euclidean distances between points.

  • Hausdorff distance. The Hausdorff distance replaces each sum by a maximum and uses plain distances: max⁡(max⁡xmin⁡y∥x−y∥,max⁡ymin⁡x∥x−y∥)\max(\max_{x} \min_{y} \|x - y\|, \max_{y} \min_{x} \|x - y\|). It is a metric on finite sets. Each term of dCDd_{\mathrm{CD}} is at most its square, so dCD≤(∣S1∣+∣S2∣)⋅dH2d_{\mathrm{CD}} \le (|S_1| + |S_2|) \cdot d_H^2, and the mean form with plain distances is at most 2dH2 d_H. One far outlier sets the Hausdorff distance, but it is only one term in the chamfer sum.
  • Earth mover's distance. For two sets of the same size, it is the smallest mean distance over all one-to-one matches, an assignment problem. It sees densities, but it costs much more to compute.
  • Registration costs. The cost that ICP lowers at each step is the one-sided chamfer distance from the moved source to the target, and some non-rigid registration methods use the two-sided form as their data term.

References

  1. Haoqiang Fan, Hao Su and Leonidas Guibas, A point set generation network for 3D object reconstruction from a single image, Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR 2017), Section 4.3, the Chamfer distance as the sum, in both directions, of the squared distance from each point to its nearest neighbour in the other set, used as a loss beside the earth mover's distance
  2. H. G. Barrow, J. M. Tenenbaum, R. C. Bolles and H. C. Wolf, Parametric correspondence and chamfer matching: two new techniques for image matching, Proceedings of the 5th International Joint Conference on Artificial Intelligence (IJCAI 1977), 659-663, Chamfer matching: an edge template is scored by the values of a distance transform of the image edges under its points

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW4 complete
  • a review of the text: no review record reviews/J3N3YK/text.yaml