Example #1
0
def patches_batch_tos_area_p(batch_image, i, j, l):
    tree, altitudes = hg.component_tree_tree_of_shapes_image2d(
        batch_image[i, :, :, 0])
    area = hg.attribute_area(tree)
    batch_image[i, :, :,
                j + 1] = hg.reconstruct_leaf_data(tree, altitudes, area < l)
    return batch_image[i, :, :, j + 1]
Example #2
0
 def test_type_consistency(self):
     tree = hg.Tree((2, 2, 2))
     for t in (np.bool, np.int8, np.uint8, np.int16, np.uint16, np.int32,
               np.uint32, np.int64, np.uint64, np.float, np.double):
         a = np.zeros(3, dtype=t)
         res = hg.reconstruct_leaf_data(tree, a)
         self.assertTrue(a.dtype == res.dtype)
Example #3
0
    def test_reconstruct_leaf_data_component_tree_default(self):
        g = hg.get_4_adjacency_implicit_graph((1, 6))
        vertex_values = np.asarray((1, 5, 4, 3, 3, 6), dtype=np.int32)
        tree, altitudes = hg.component_tree_max_tree(g, vertex_values)

        area = hg.attribute_area(tree)
        output = hg.reconstruct_leaf_data(tree, area)
        ref = np.asarray((6, 1, 2, 5, 5, 1), dtype=np.int32)

        self.assertTrue(np.all(ref == output))
Example #4
0
    def test_reconstruct_leaf_data_component_tree(self):
        g = hg.get_4_adjacency_implicit_graph((1, 6))
        vertex_values = np.asarray((1, 5, 4, 3, 3, 6), dtype=np.int32)
        tree, altitudes = hg.component_tree_max_tree(g, vertex_values)

        condition = np.asarray((True, False, True, False, True, True, False, True, False, True, False), np.bool_)

        output = hg.reconstruct_leaf_data(tree, altitudes, condition)
        ref = np.asarray((1, 4, 4, 1, 1, 6), dtype=np.int32)

        self.assertTrue(np.all(ref == output))
Example #5
0
def patches_batch_tos_area(batch_image, batch_size, lambdas):
    for i in range(batch_size):
        tree, altitudes = hg.component_tree_tree_of_shapes_image2d(
            batch_image[i, :, :, 0])
        area = hg.attribute_area(tree)

        for j in range(len(lambdas)):
            batch_image[i, :, :, j + 1] = hg.reconstruct_leaf_data(
                tree, altitudes, area < lambdas[j])

    return batch_image
Example #6
0
    def test_reconstruct_leaf_data_default(self):
        tree = hg.Tree(np.asarray((5, 5, 6, 6, 6, 7, 7, 7)))

        input = np.asarray(
            ((1, 8), (2, 7), (3, 6), (4, 5), (5, 4), (6, 3), (7, 2), (8, 1)),
            dtype=np.int32)

        output = hg.reconstruct_leaf_data(tree, input)
        ref = np.asarray(((1, 8), (2, 7), (3, 6), (4, 5), (5, 4)),
                         dtype=np.int32)

        self.assertTrue(np.all(ref == output))
Example #7
0
    def test_reconstruct_leaf_data(self):
        tree = hg.Tree(np.asarray((5, 5, 6, 6, 6, 7, 7, 7)))

        input = np.asarray(
            ((1, 8), (2, 7), (3, 6), (4, 5), (5, 4), (6, 3), (7, 2), (8, 1)),
            dtype=np.int32)

        condition = np.asarray(
            (True, False, True, False, True, True, False, False), np.bool_)

        output = hg.reconstruct_leaf_data(tree, input, condition)
        ref = np.asarray(((8, 1), (2, 7), (7, 2), (4, 5), (7, 2)),
                         dtype=np.int32)

        self.assertTrue(np.all(ref == output))
Example #8
0
    def test_simplify_tree_propagate_category(self):
        g = hg.get_4_adjacency_implicit_graph((1, 6))
        vertex_values = np.asarray((1, 5, 4, 3, 3, 6), dtype=np.int32)
        tree, altitudes = hg.component_tree_max_tree(g, vertex_values)

        condition = np.asarray((False, False, False, False, False, False,
                                False, True, False, True, False), np.bool)

        new_tree, node_map = hg.simplify_tree(tree, condition)

        self.assertTrue(
            np.all(new_tree.parents() == (8, 7, 7, 8, 8, 6, 8, 8, 8)))
        self.assertTrue(np.all(node_map == (0, 1, 2, 3, 4, 5, 6, 8, 10)))
        self.assertTrue(new_tree.category() == hg.TreeCategory.ComponentTree)

        rec = hg.reconstruct_leaf_data(new_tree, altitudes[node_map])
        self.assertTrue(np.all(rec == (1, 4, 4, 1, 1, 6)))
Example #9
0
    def test_area_filter_max_tree(self):
        graph = hg.get_4_adjacency_implicit_graph((5, 5))
        vertex_weights = np.asarray(
            ((-5, 2, 2, 5, 5), (-4, 2, 2, 6, 5), (3, 3, 3, 3, 3),
             (-2, -2, -2, 9, 7), (-1, 0, -2, 8, 9)),
            dtype=np.float64)
        tree, altitudes = hg.component_tree_max_tree(graph, vertex_weights)
        area = hg.attribute_area(tree)

        filtered_weights = hg.reconstruct_leaf_data(tree, altitudes, area <= 4)

        expected_filtered_weights = \
            np.asarray(((-5, 2, 2, 3, 3),
                        (-4, 2, 2, 3, 3),
                        (3, 3, 3, 3, 3),
                        (-2, -2, -2, 3, 3),
                        (-2, -2, -2, 3, 3)), dtype=np.float64)

        self.assertTrue(np.all(filtered_weights == expected_filtered_weights))