-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetrics.py
60 lines (50 loc) · 1.76 KB
/
metrics.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import numpy as np
__all__ = ['rms_angle_error']
def _angle_error(n_estim, n_gt, orient=True):
"""Return the angle error(s) in degrees between the estimated and
ground truth normal vector.
Parameters
----------
n_estim : numpy.ndsarray
Estimated unit normals of shape (N, 3), where N is the
number of points in the point cloud.
n_gt : numpy.ndarray
Ground truth normals of the corresponding shape.
orient : bool, optional
If it is set to True, orientation of the normals is taken
into account. Otherwise, orientation does not matter.
Returns
-------
float or numpy.ndarray
Angle error(s) in degrees.
"""
N = n_gt.shape[0]
if orient:
dot = np.sum(n_estim * n_gt, axis=1)
else:
dot = np.sum(np.abs(n_estim) * np.abs(n_gt), axis=1)
dot = np.where(dot > 1, 1, dot)
dot = np.where(dot < -1, -1, dot)
if np.sum(dot) / N == 1: # all normals matched -> no error
return 0
return np.arccos(dot) * 180 / np.pi
def rms_angle_error(n_estim, n_gt, orient=True):
"""Return the root mean square angle error between estimated and
ground truth normal vectors.
Parameters
----------
n_estim : numpy.ndsarray
Estimated unit normals of shape (N, 3), where N is the
number of points in the point cloud.
n_gt : numpy.ndarray
Ground truth normals of the corresponding shape.
orient : bool, optional
If it is set to True, orientation of the normals is taken
into account. Otherwise, orientation does not matter.
Returns
-------
float
Root mean square angle error in degrees.
"""
err = _angle_error(n_estim, n_gt, orient)
return np.sqrt(np.mean(err ** 2))