Esempio n. 1
0
def test_downsample():
    skel = Skeleton(
        [(0, 0, 0), (1, 0, 0), (1, 1, 0), (1, 1, 3), (2, 1, 3), (2, 2, 3)],
        edges=[(1, 0), (1, 2), (2, 3), (3, 4), (5, 4)],
        radii=[1, 2, 3, 4, 5, 6],
        vertex_types=[1, 2, 3, 4, 5, 6],
        segid=1337,
    )

    def should_error(x):
        try:
            skel.downsample(x)
            assert False
        except ValueError:
            pass

    should_error(-1)
    should_error(0)
    should_error(.5)
    should_error(2.00000000000001)

    dskel = skel.downsample(1)
    assert Skeleton.equivalent(dskel, skel)
    assert dskel.id == skel.id
    assert dskel.id == 1337

    dskel = skel.downsample(2)
    dskel_gt = Skeleton([(0, 0, 0), (1, 1, 0), (2, 1, 3), (2, 2, 3)],
                        edges=[(1, 0), (1, 2), (2, 3)],
                        radii=[1, 3, 5, 6],
                        vertex_types=[1, 3, 5, 6])
    assert Skeleton.equivalent(dskel, dskel_gt)

    dskel = skel.downsample(3)
    dskel_gt = Skeleton(
        [(0, 0, 0), (1, 1, 3), (2, 2, 3)],
        edges=[(1, 0), (1, 2)],
        radii=[1, 4, 6],
        vertex_types=[1, 4, 6],
    )
    assert Skeleton.equivalent(dskel, dskel_gt)

    skel = Skeleton([(0, 0, 0), (1, 0, 0), (1, 1, 0), (1, 1, 3), (2, 1, 3),
                     (2, 2, 3)],
                    edges=[(1, 0), (1, 2), (3, 4), (5, 4)],
                    radii=[1, 2, 3, 4, 5, 6],
                    vertex_types=[1, 2, 3, 4, 5, 6])
    dskel = skel.downsample(2)
    dskel_gt = Skeleton([(0, 0, 0), (1, 1, 0), (1, 1, 3), (2, 2, 3)],
                        edges=[(1, 0), (2, 3)],
                        radii=[1, 3, 4, 6],
                        vertex_types=[1, 3, 4, 6])
    assert Skeleton.equivalent(dskel, dskel_gt)
Esempio n. 2
0
def test_downsample_joints():
    skel = Skeleton(
        [
            (2, 3, 0),  # 0
            (2, 2, 0),  # 1
            (2, 1, 0),  # 2
            (0, 0, 0),
            (1, 0, 0),
            (2, 0, 0),
            (3, 0, 0),
            (4, 0, 0),  # 3, 4, 5, 6, 7
            (2, -1, 0),  # 8
            (2, -2, 0),  # 9
            (2, -3, 0),  # 10
        ],
        edges=[(0, 1), (1, 2), (2, 5), (3, 4), (4, 5), (5, 6), (6, 7), (5, 8),
               (8, 9), (9, 10)],
        radii=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
        vertex_types=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
        segid=1337,
    )

    ds_skel = skel.downsample(2)
    ds_skel_gt = Skeleton(
        [
            (2, 3, 0),  # 0
            (2, 2, 0),  # 1
            (0, 0, 0),
            (2, 0, 0),
            (4, 0, 0),  # 2, 3, 4
            (2, -2, 0),  # 5                        
            (2, -3, 0),  # 6
        ],
        edges=[(0, 1), (1, 3), (2, 3), (3, 4), (3, 5), (5, 6)],
        radii=[0, 1, 3, 5, 7, 9, 10],
        vertex_types=[0, 1, 3, 5, 7, 9, 10],
        segid=1337,
    )

    assert Skeleton.equivalent(ds_skel, ds_skel_gt)