def updatecolor():
                global c0, c1, c2, showpoints
                if colorflag:
                    showpoints = np.vstack([ptcloud[i][::1], pred[i]])

                    value = distmap[i] / distmap[i].max()
                    rgb = np.zeros((len(value), 3), dtype='float32')
                    rgb[:, 2] = (value * 2).clip(0, 1) * 255
                    rgb[:, 1] = (2 - value * 2).clip(0, 1) * 255
                    c0 = np.hstack([rgb[:, 1][::1], np.zeros(len(pred[i]))])
                    c1 = np.hstack([rgb[:, 2][::1], np.zeros(len(pred[i]))])
                    c2 = np.hstack([rgb[:, 0][::1], np.ones(len(pred[i]))])

                else:
                    showpoints = np.vstack([pred[i]])

                    a = pred[i]
                    b = ptcloud[i]
                    hausdorff_a_to_b = pcu.hausdorff(a, b)
                    hausdorff_b_to_a = pcu.hausdorff(b, a)
                    hausdorff_dist = max(hausdorff_a_to_b, hausdorff_b_to_a)
                    print("hausdorff_dist", hausdorff_dist)

                    M = pcu.pairwise_distances(a, b)
                    w_a = np.ones(a.shape[0], dtype='float32')
                    w_b = np.ones(b.shape[0], dtype='float32')
                    P = pcu.sinkhorn(w_a, w_b, M, eps=1e-3)
                    sinkhorn_dist = (M * P).sum()
                    print("sinkhorn_dist", sinkhorn_dist)
                    '''
Esempio n. 2
0
    def test_sinkhorn(self):
        import point_cloud_utils as pcu
        import numpy as np

        # a and b are arrays where each row contains a point
        # Note that the point sets can have different sizes (e.g [100, 3], [111, 3])
        a = np.random.rand(100, 3)
        b = np.random.rand(100, 3)

        # M is a 100x100 array where each entry  (i, j) is the squared distance between point a[i, :] and b[j, :]
        M = pcu.pairwise_distances(a, b)

        # w_a and w_b are masses assigned to each point. In this case each point is weighted equally.
        w_a = np.ones(a.shape[0])
        w_b = np.ones(b.shape[0])

        # P is the transport matrix between a and b, eps is a regularization parameter, smaller epsilons lead to
        # better approximation of the true Wasserstein distance at the expense of slower convergence
        P = pcu.sinkhorn(w_a, w_b, M, eps=1e-3)

        # To get the distance as a number just compute the frobenius inner product <M, P>
        sinkhorn_dist = (M * P).sum()