Esempio n. 1
0
    def contour_2_khalimsky(graph, shape, contour):
        res_shape = (shape[0] * 2 - 1, shape[1] * 2 - 1)
        result = np.zeros(res_shape, np.int64)

        embedding = hg.EmbeddingGrid2d(shape)
        count = 0

        def edge_to_k(edge_index):
            e = graph.edge_from_index(edge_index)
            s = e[0]
            t = e[1]

            ti = embedding.lin2grid(t)
            si = embedding.lin2grid(s)
            return ti + si

        for polyline in contour:
            for segment in polyline:
                count += 1
                for e in segment:
                    p = edge_to_k(e[0])
                    result[p[0], p[1]] = count

                p = edge_to_k(segment[0][0])
                result[p[0], p[1]] = -1 * count
                p = edge_to_k(segment[len(segment) - 1][0])
                result[p[0], p[1]] = -1 * count

        return result
Esempio n. 2
0
    def test_create_graph(self):
        shape = (2, 3)
        nl = ((-1, 0), (0, -1), (0, 1), (1, 0))
        g1 = hg.RegularGraph2d(hg.EmbeddingGrid2d(shape), nl)

        g2 = hg.get_4_adjacency_implicit_graph(shape)
        g3 = hg.get_8_adjacency_implicit_graph(shape)

        for g in (g1, g2, g3):
            self.assertTrue(g.num_vertices() == 6)
Esempio n. 3
0
    def test_grid2linV(self):
        e1 = hg.EmbeddingGrid2d((5, 10))

        coord = np.asarray((((0, 0), (0, 1), (0, 2), (0, 3)),
                            ((2, 2), (4, 2), (4, 3), (4, 4))),
                           dtype=np.int64)
        ref = np.asarray(((0, 1, 2, 3), (22, 42, 43, 44)), dtype=np.uint64)

        res = e1.grid2lin(coord)
        self.assertTrue(np.array_equal(ref, res))
Esempio n. 4
0
    def test_containsV(self):
        e1 = hg.EmbeddingGrid2d((5, 10))
        coords = np.asarray(
            (((0, 0), (3, 8), (-1, 2)), ((2, 4), (5, 5), (43, 44))),
            dtype=np.int64)

        ref = np.asarray(((True, True, False), (True, False, False)))

        res = e1.contains(coords)

        self.assertTrue(np.array_equal(ref, res))
Esempio n. 5
0
    def test_create_graph(self):
        shape = (2, 3)
        nl = ((-1, 0), (0, -1), (0, 1), (1, 0))
        g1 = hg.RegularGraph2d(hg.EmbeddingGrid2d(shape), nl)

        g2 = hg.get_4_adjacency_implicit_graph(shape)
        g3 = hg.get_8_adjacency_implicit_graph(shape)

        for g in (g1, g2, g3):
            self.assertTrue(g.num_vertices() == 6)

        self.assertTrue(np.all(g1.shape() == shape))
        self.assertTrue(np.all(g1.neighbour_list() == nl))

        g4 = hg.RegularGraph2d(g1.shape(), g1.neighbour_list())
        self.assertTrue(np.all(g4.shape() == shape))
        self.assertTrue(np.all(g4.neighbour_list() == nl))