Ultralytics YOLO27: Join the waitlist.
License YOLO
Back to Ultralytics Glossary

Chamfer Distance

Chamfer distance measures how closely point sets, 3D surfaces, or object boundaries match, supporting reconstruction, segmentation, and model training.

Chamfer distance is a measure of how closely two sets of points match, calculated from the distance between each point and its nearest neighbor in the other set. Lower values indicate closer agreement. In computer vision, it compares 3D point clouds—collections of sampled spatial coordinates—and 2D object boundaries. Point order is irrelevant, and the sets can contain different numbers of points.

Its origins lie in chamfer matching, introduced by H. G. Barrow, J. M. Tenenbaum, R. C. Bolles, and H. C. Wolf in 1977 for matching shapes represented by image curves. In mechanical CAD, a chamfer is a beveled edge whose dimensions describe a physical feature.

How Chamfer Distance Is Calculated#

For two nonempty point sets, A and B, a common squared-distance definition has three steps:

  1. Find each point in A's nearest neighbor in B, square the Euclidean distance, and average these values.
  2. Repeat from B to A.
  3. Add the two directional averages.

The first direction penalizes predicted points far from the reference surface; the reverse direction penalizes reference regions missing from the prediction. This uses the same nearest-neighbor operation underlying k-nearest neighbors, with one neighbor per query. PyTorch3D's Chamfer implementation supports both bidirectional and single-directional calculations.

Squared versus unsquared distances and sum versus mean reductions change the score. Another common convention averages the two directional means, producing half the value of their sum. Consequently, the distance convention, coordinate units, and normalization are part of the metric's definition for an experiment.

This PyTorch calculation uses torch.cdist to compute pairwise Euclidean distances:

import torch

a = torch.tensor([[0.0, 0.0], [2.0, 0.0]])
b = torch.tensor([[0.0, 0.0], [3.0, 0.0]])

# Reduce squared distances in each nearest-neighbor direction.
distances = torch.cdist(a, b, p=2)
squared_distances = distances.square()
a_to_b = squared_distances.min(dim=1).values.mean()
b_to_a = squared_distances.min(dim=0).values.mean()
chamfer = a_to_b + b_to_a

print(f"Squared Chamfer distance: {chamfer.item():.2f}")

The output is 1.00: each directional average is 0.50. Identical point sets produce zero.

Chamfer Loss in Model Training#

Chamfer loss means Chamfer distance used as a loss function. A neural network predicts point coordinates, and backpropagation supplies gradients that move them toward reference points. Nearest-neighbor selection makes the objective piecewise differentiable: within a region where assignments stay fixed, squared distances provide coordinate gradients.

A foundational application is Point Set Generation Network (PSGN) by Haoqiang Fan, Hao Su, and Leonidas J. Guibas, presented at CVPR 2017. It uses Chamfer distance as a training objective for single-image 3D reconstruction, predicting an object's point cloud from a photograph. This point-set objective supports learning without predefined point-to-point correspondences.

Applications in Reconstruction and Segmentation#

In 3D reconstruction, Chamfer distance compares sampled predicted surfaces with reference geometry. It also supports mesh fitting: vertices are optimized so that samples from the mesh approach target samples. In sphere-to-dolphin mesh fitting, optimizing Chamfer loss alone produces an uneven surface; edge, normal, and Laplacian regularization constrain local mesh structure.

For instance segmentation, Chamfer distance measures spatial disagreement between sampled predicted and annotated contours. Ultralytics YOLO26 segmentation exposes polygon coordinates through Masks.xy, providing point sets for external Chamfer-based boundary evaluation. Unlike area-based Intersection over Union, contour distance expresses how far boundaries lie apart.

Three related concepts clarify what the score captures:

  • Hausdorff distance uses the largest nearest-neighbor discrepancy, emphasizing the worst boundary or surface mismatch.
  • Earth Mover's distance finds a minimum-cost, mass-preserving transport between distributions, coupling assignments across the point sets.
  • Density-aware Chamfer distance addresses uneven local sampling. Ordinary Chamfer matching permits many points to share one nearest neighbor, so dense clusters can receive small errors despite poor sampling uniformity.

Sampling density, alignment, and data preprocessing therefore affect comparisons. Unsquared distance has the coordinate unit; squared distance has its square. Converting both clouds from meters to centimeters multiplies unsquared Chamfer distance by 100 and squared Chamfer distance by 10,000.

Explore solutions

Computer vision in sports

Computer vision in sports

Discover how Ultralytics YOLO powers sports vision with player and ball tracking, performance analytics, coaching insights, and athlete rehabilitation.
Learn more
Computer vision for aerial imagery

Computer vision for aerial imagery

Transform drone and aerial imagery into real-time insights for agriculture, aquaculture, environmental monitoring, conservation, and geospatial analysis with Ultralytics YOLO.
Learn more
Computer vision in aerospace

Computer vision in aerospace

Bring vision AI to aerial monitoring with Ultralytics YOLO models. Power drones, aerospace workflows, environmental conservation & geospatial industries with computer vision solutions.
Learn more
Computer vision in security

Computer vision in security

Protect every site with Ultralytics YOLO models. Vision AI powers perimeter monitoring, threat detection, license-plate recognition, and workplace safety.
Learn more
Computer vision in robotics

Computer vision in robotics

Power smarter machines with Ultralytics YOLO models. Vision AI in robotics drives autonomous navigation, perception, object tracking, and real-time control.
Learn more
Computer vision in logistics

Computer vision in logistics

Streamline logistics with Ultralytics YOLO models. Vision AI enables package inspection, sorting, vehicle tracking, and real-time warehouse safety monitoring.
Learn more
Computer vision in retail

Computer vision in retail

Reimagine retail with Ultralytics YOLO models. Vision AI powers inventory tracking, shelf monitoring, queue management, and smarter customer insights.
Learn more
Computer vision in healthcare

Computer vision in healthcare

Build healthcare solutions with Ultralytics YOLO models. Vision AI in healthcare powers faster medical imaging, smarter diagnostics, and patient monitoring.
Learn more
Computer vision in manufacturing

Computer vision in manufacturing

Optimize manufacturing with Ultralytics YOLO models. Vision AI drives quality control, defect detection, PPE compliance, and assembly line automation.
Learn more
Computer vision in automotive

Computer vision in automotive

Apply computer vision in automotive with Ultralytics YOLO models. Vision AI elevates road safety, driver assistance, and vehicle automation for smarter roads.
Learn more
Computer vision in agriculture

Computer vision in agriculture

Bring vision AI to smart agriculture with Ultralytics YOLO models. Power crop monitoring, livestock tracking, and precision farming for higher, smarter yields.
Learn more
Computer vision in sports

Computer vision in sports

Discover how Ultralytics YOLO powers sports vision with player and ball tracking, performance analytics, coaching insights, and athlete rehabilitation.
Learn more
Computer vision for aerial imagery

Computer vision for aerial imagery

Transform drone and aerial imagery into real-time insights for agriculture, aquaculture, environmental monitoring, conservation, and geospatial analysis with Ultralytics YOLO.
Learn more
Computer vision in aerospace

Computer vision in aerospace

Bring vision AI to aerial monitoring with Ultralytics YOLO models. Power drones, aerospace workflows, environmental conservation & geospatial industries with computer vision solutions.
Learn more
Computer vision in security

Computer vision in security

Protect every site with Ultralytics YOLO models. Vision AI powers perimeter monitoring, threat detection, license-plate recognition, and workplace safety.
Learn more
Computer vision in robotics

Computer vision in robotics

Power smarter machines with Ultralytics YOLO models. Vision AI in robotics drives autonomous navigation, perception, object tracking, and real-time control.
Learn more
Computer vision in logistics

Computer vision in logistics

Streamline logistics with Ultralytics YOLO models. Vision AI enables package inspection, sorting, vehicle tracking, and real-time warehouse safety monitoring.
Learn more
Computer vision in retail

Computer vision in retail

Reimagine retail with Ultralytics YOLO models. Vision AI powers inventory tracking, shelf monitoring, queue management, and smarter customer insights.
Learn more
Computer vision in healthcare

Computer vision in healthcare

Build healthcare solutions with Ultralytics YOLO models. Vision AI in healthcare powers faster medical imaging, smarter diagnostics, and patient monitoring.
Learn more
Computer vision in manufacturing

Computer vision in manufacturing

Optimize manufacturing with Ultralytics YOLO models. Vision AI drives quality control, defect detection, PPE compliance, and assembly line automation.
Learn more
Computer vision in automotive

Computer vision in automotive

Apply computer vision in automotive with Ultralytics YOLO models. Vision AI elevates road safety, driver assistance, and vehicle automation for smarter roads.
Learn more
Computer vision in agriculture

Computer vision in agriculture

Bring vision AI to smart agriculture with Ultralytics YOLO models. Power crop monitoring, livestock tracking, and precision farming for higher, smarter yields.
Learn more
Computer vision in sports

Computer vision in sports

Discover how Ultralytics YOLO powers sports vision with player and ball tracking, performance analytics, coaching insights, and athlete rehabilitation.
Learn more
Computer vision for aerial imagery

Computer vision for aerial imagery

Transform drone and aerial imagery into real-time insights for agriculture, aquaculture, environmental monitoring, conservation, and geospatial analysis with Ultralytics YOLO.
Learn more
Computer vision in aerospace

Computer vision in aerospace

Bring vision AI to aerial monitoring with Ultralytics YOLO models. Power drones, aerospace workflows, environmental conservation & geospatial industries with computer vision solutions.
Learn more
Computer vision in security

Computer vision in security

Protect every site with Ultralytics YOLO models. Vision AI powers perimeter monitoring, threat detection, license-plate recognition, and workplace safety.
Learn more
Computer vision in robotics

Computer vision in robotics

Power smarter machines with Ultralytics YOLO models. Vision AI in robotics drives autonomous navigation, perception, object tracking, and real-time control.
Learn more
Computer vision in logistics

Computer vision in logistics

Streamline logistics with Ultralytics YOLO models. Vision AI enables package inspection, sorting, vehicle tracking, and real-time warehouse safety monitoring.
Learn more
Computer vision in retail

Computer vision in retail

Reimagine retail with Ultralytics YOLO models. Vision AI powers inventory tracking, shelf monitoring, queue management, and smarter customer insights.
Learn more
Computer vision in healthcare

Computer vision in healthcare

Build healthcare solutions with Ultralytics YOLO models. Vision AI in healthcare powers faster medical imaging, smarter diagnostics, and patient monitoring.
Learn more
Computer vision in manufacturing

Computer vision in manufacturing

Optimize manufacturing with Ultralytics YOLO models. Vision AI drives quality control, defect detection, PPE compliance, and assembly line automation.
Learn more
Computer vision in automotive

Computer vision in automotive

Apply computer vision in automotive with Ultralytics YOLO models. Vision AI elevates road safety, driver assistance, and vehicle automation for smarter roads.
Learn more
Computer vision in agriculture

Computer vision in agriculture

Bring vision AI to smart agriculture with Ultralytics YOLO models. Power crop monitoring, livestock tracking, and precision farming for higher, smarter yields.
Learn more

Let's build the future of AI together!

Begin your journey with the future of machine learning