예제 #1
0
    def test_cube_vertex_iter(self):
        # This test can fail if IterativeVoting do not work correctly.
        data = np.zeros((50, 50, 50), dtype=np.uint8)
        data[2:-2, 2:-2, 2:-2] = 1

        for i in range(2, 4):
            res = IterativeVoteSmoothing.smooth(
                data, {
                    "neighbourhood_type": NeighType.vertex,
                    "support_level": 7,
                    "max_steps": i
                })
            assert np.all(data == res), f"Fail  on step {i}"
        for support_level in range(8, 19):
            res2 = VoteSmoothing.smooth(
                data, {
                    "neighbourhood_type": NeighType.vertex,
                    "support_level": support_level
                })
            for i in range(2, 8):
                res = IterativeVoteSmoothing.smooth(
                    data, {
                        "neighbourhood_type": NeighType.vertex,
                        "support_level": support_level,
                        "max_steps": i
                    })
                res2 = VoteSmoothing.smooth(
                    res2, {
                        "neighbourhood_type": NeighType.vertex,
                        "support_level": support_level
                    })
                assert np.all(
                    res2 == res
                ), f"Fail  on step {i} for support level {support_level}"
예제 #2
0
 def test_square_vertex(self):
     data = np.zeros((1, 50, 50), dtype=np.uint8)
     data[:, 2:-2, 2:-2] = 1
     res = VoteSmoothing.smooth(data, {
         "neighbourhood_type": NeighType.vertex,
         "support_level": 1
     })
     assert np.all(res == data)
     res = VoteSmoothing.smooth(data, {
         "neighbourhood_type": NeighType.vertex,
         "support_level": 3
     })
     assert np.all(res == data)
     res = VoteSmoothing.smooth(data, {
         "neighbourhood_type": NeighType.vertex,
         "support_level": 4
     })
     res2 = np.copy(data)
     for pos in itertools.product([2, -3], repeat=2):
         res2[(0, ) + pos] = 0
     assert np.all(res2 == res)
     res = VoteSmoothing.smooth(data, {
         "neighbourhood_type": NeighType.vertex,
         "support_level": 5
     })
     assert np.all(res2 == res)
     res = VoteSmoothing.smooth(data, {
         "neighbourhood_type": NeighType.vertex,
         "support_level": 6
     })
     res2 = np.zeros(data.shape, dtype=data.dtype)
     res2[:, 3:-3, 3:-3] = 1
     assert np.all(res == res2)
예제 #3
0
    def test_cube_edge_iter(self):
        # This test can fail if IterativeVoting do not work correctly.
        data = np.zeros((50, 50, 50), dtype=np.uint8)
        data[2:-2, 2:-2, 2:-2] = 1
        res2 = np.copy(data)
        for pos in itertools.product([2, -3], repeat=3):
            res2[pos] = 0

        for i in range(2, 4):
            res = IterativeVoteSmoothing.smooth(
                data, {
                    "neighbourhood_type": NeighType.edges,
                    "support_level": 7,
                    "max_steps": i
                })
            assert np.all(res2 == res), f"Fail  on step {i}"
        for support_level in [8, 9, 10, 11, 12]:
            res2 = VoteSmoothing.smooth(
                data, {
                    "neighbourhood_type": NeighType.edges,
                    "support_level": support_level
                })
            for i in range(2, 8):
                res = IterativeVoteSmoothing.smooth(
                    data, {
                        "neighbourhood_type": NeighType.edges,
                        "support_level": support_level,
                        "max_steps": i
                    })
                res2 = VoteSmoothing.smooth(
                    res2, {
                        "neighbourhood_type": NeighType.edges,
                        "support_level": support_level
                    })
                assert np.all(
                    res2 == res
                ), f"Fail  on step {i} for support level {support_level}"
예제 #4
0
 def test_cube_sides(self):
     data = np.zeros((50, 50, 50), dtype=np.uint8)
     data[2:-2, 2:-2, 2:-2] = 1
     res = VoteSmoothing.smooth(data, {
         "neighbourhood_type": NeighType.sides,
         "support_level": 1
     })
     assert np.all(res == data)
     res = VoteSmoothing.smooth(data, {
         "neighbourhood_type": NeighType.sides,
         "support_level": 3
     })
     assert np.all(res == data)
     res = VoteSmoothing.smooth(data, {
         "neighbourhood_type": NeighType.sides,
         "support_level": 4
     })
     res2 = np.copy(data)
     for pos in itertools.product([2, -3], repeat=3):
         res2[pos] = 0
     assert np.all(res2 == res)
     res = VoteSmoothing.smooth(data, {
         "neighbourhood_type": NeighType.sides,
         "support_level": 5
     })
     res2 = np.copy(data)
     for pos in itertools.permutations([2, 2, -3, -3, slice(2, -2)], 3):
         res2[pos] = 0
     assert np.all(res2 == res)
     res = VoteSmoothing.smooth(data, {
         "neighbourhood_type": NeighType.sides,
         "support_level": 6
     })
     res2 = np.zeros(data.shape, dtype=data.dtype)
     res2[3:-3, 3:-3, 3:-3] = 1
     assert np.all(res2 == res)