Ejemplo n.º 1
0
    def test_component_tree_multivariate_tree_of_shapes_image2d_fill_hole(self):
        im1 = np.asarray((0, 0, 0, 0, 0, 0, 0,
                          0, 1, 1, 1, 0, 0, 0,
                          0, 1, 0, 0, 0, 0, 0,
                          0, 1, 0, -1, 0, 0, 0,
                          0, 1, 0, 0, 0, 0, 0,
                          0, 1, 1, 1, 0, 0, 0), dtype=np.float32).reshape((6, 7))

        im2 = np.asarray((0, 0, 0, 0, 0, 0, 0,
                          0, 0, 0, 1, 1, 1, 0,
                          0, 0, 0, 0, 0, 1, 0,
                          0, 0, 0, 0, 0, 1, 0,
                          0, 0, 0, 0, 0, 1, 0,
                          0, 0, 0, 1, 1, 1, 0), dtype=np.float32).reshape((6, 7))
        image = np.dstack((im1, im2))

        tree = hg.component_tree_multivariate_tree_of_shapes_image2d(image, padding='none', immersion=False)

        ref_tree = hg.Tree((44, 44, 44, 44, 44, 44, 44,
                            44, 43, 43, 43, 43, 43, 44,
                            44, 43, 43, 43, 43, 43, 44,
                            44, 43, 43, 42, 43, 43, 44,
                            44, 43, 43, 43, 43, 43, 44,
                            44, 43, 43, 43, 43, 43, 44, 43, 44, 44))
        self.assertTrue(hg.test_tree_isomorphism(tree, ref_tree))
Ejemplo n.º 2
0
    def test_component_tree_multivariate_tree_of_shapes_image2d_2(self):
        im1 = np.asarray((0, 0, 0, 0, 0, 0, 0,
                          3, 3, 3, 2, 1, 1, 1,
                          3, 3, 3, 2, 1, 1, 1,
                          3, 3, 3, 2, 1, 1, 1,
                          2, 2, 2, 2, 1, 1, 1,
                          1, 1, 1, 1, 1, 0, 0), dtype=np.float32).reshape((6, 7))

        im2 = np.asarray((0, 0, 0, 0, 0, 0, 0,
                          0, 0, 0, 0, 0, 0, 0,
                          0, 2, 1, 1, 1, 2, 0,
                          0, 1, 1, 1, 1, 2, 0,
                          0, 0, 0, 0, 0, 0, 0,
                          0, 0, 0, 0, 0, 0, 0), dtype=np.float32).reshape((6, 7))
        image = np.dstack((im1, im2))

        tree = hg.component_tree_multivariate_tree_of_shapes_image2d(image, 'zero')

        ref_tree = hg.Tree((47, 47, 47, 47, 47, 47, 47,
                            43, 43, 43, 45, 46, 46, 46,
                            43, 42, 43, 45, 45, 44, 46,
                            43, 43, 43, 45, 45, 44, 46,
                            45, 45, 45, 45, 46, 46, 46,
                            46, 46, 46, 46, 46, 47, 47, 43, 45, 45, 46, 47, 47))
        self.assertTrue(hg.test_tree_isomorphism(tree, ref_tree))
Ejemplo n.º 3
0
    def test_component_tree_multivariate_tree_of_shapes_image2d_1(self):
        im1 = np.asarray((2, 1, 0, 0, -1, -2), dtype=np.float32).reshape((1, 6))
        im2 = np.asarray((1, 2, 0, -2, -1, 0), dtype=np.float32).reshape((1, 6))
        image = np.dstack((im1, im2))

        tree = hg.component_tree_multivariate_tree_of_shapes_image2d(image, 'zero')

        ref_tree = hg.Tree((6, 7, 12, 8, 11, 9, 10, 10, 11, 11, 12, 12, 12))
        self.assertTrue(hg.test_tree_isomorphism(tree, ref_tree))
Ejemplo n.º 4
0
    def test_component_tree_multivariate_tree_of_shapes_image2d_sanity(self):
        image = np.asarray(((1, 1),
                            (1, -2),
                            (1, 7)), dtype=np.float64)

        tree, _ = hg.component_tree_tree_of_shapes_image2d(image, 'mean')

        image3d = np.dstack((image, image, image))
        tree2 = hg.component_tree_multivariate_tree_of_shapes_image2d(image3d, 'mean')

        self.assertTrue(hg.test_tree_isomorphism(tree, tree2))
Ejemplo n.º 5
0
    def test_component_tree_multivariate_tree_of_shapes_image2d_no_padding_no_immersion_original_size(self):
        im1 = np.asarray((0, 0, 0, 0, 0,
                          0, 2, 1, 0, 0,
                          0, 0, 0, 0, 0), dtype=np.float32).reshape((3, 5))
        im2 = np.asarray((0, 0, 0, 0, 0,
                          0, 0, 1, 2, 0,
                          0, 0, 0, 0, 0), dtype=np.float32).reshape((3, 5))
        image = np.dstack((im1, im2))

        tree = hg.component_tree_multivariate_tree_of_shapes_image2d(image, 'none', original_size=True, immersion=False)

        ref_tree = hg.Tree((18, 18, 18, 18, 18, 18, 15, 17, 16, 18, 18, 18, 18, 18, 18, 17, 17, 18, 18))
        self.assertTrue(hg.test_tree_isomorphism(tree, ref_tree))
Ejemplo n.º 6
0
    def test_component_tree_multivariate_tree_of_shapes_image2d_no_original_size(self):
        im1 = np.asarray((2, 1, 2), dtype=np.float32).reshape((1, 3))
        im2 = np.asarray((2, 2, 1), dtype=np.float32).reshape((1, 3))
        image = np.dstack((im1, im2))

        tree = hg.component_tree_multivariate_tree_of_shapes_image2d(image, 'zero', original_size=False)

        ref_tree = hg.Tree((48, 48, 48, 48, 48, 48, 48, 48, 48,
                            48, 48, 48, 48, 48, 48, 48, 48, 48,
                            48, 48, 45, 45, 45, 47, 46, 48, 48,
                            48, 48, 48, 48, 48, 48, 48, 48, 48,
                            48, 48, 48, 48, 48, 48, 48, 48, 48, 47, 47, 48, 48))
        self.assertTrue(hg.test_tree_isomorphism(tree, ref_tree))