point-cloud-utils icon indicating copy to clipboard operation
point-cloud-utils copied to clipboard

Potential Error in Chamfer Distance Calculation

Open samuelss1996 opened this issue 1 year ago • 0 comments

Description

I noticed a potential issue in the calculation of the Chamfer Distance within the codebase. Specifically, the current implementation sums the mean distances rather than taking the average.

Current Implementation

In the current implementation, the Chamfer Distance is calculated as follows:

https://github.com/fwilliams/point-cloud-utils/blob/387b84f658efc10464e7c3cf5bed5f54c1c711e3/point_cloud_utils/init.py#L115

Issue

The Chamfer Distance is typically defined as the average of the mean distances, not the sum. This is in fact, what is written in the project's documentation:

$$ \text{chamfer}(P_1, P_2) = \frac{1}{2n} \sum_{x \in P_1} |x - \text{NN}(x, P_2)| + \frac{1}{2m} \sum_{x \in P_2} |x - \text{NN}(x, P_1)| $$

Source: https://github.com/fwilliams/point-cloud-utils/blob/master/docs/docs/sections/shape_metrics.md#chamfer-distance

The current method calculates the sum of the mean distances, thus performing the following computation instead:

$$ \text{chamfer}(P_1, P_2) = \frac{1}{n} \sum_{x \in P_1} |x - \text{NN}(x, P_2)| + \frac{1}{m} \sum_{x \in P_2} |x - \text{NN}(x, P_1)| $$

(notice the change in the denominators with respect to the original equation)

Proposed Fix

The correct calculation should take the average of these distances:

cham_dist = (np.mean(dists_x_to_y) + np.mean(dists_y_to_x)) / 2

samuelss1996 avatar Jun 05 '24 19:06 samuelss1996