Exemplo n.º 1
0
    def test_attribute_volume(self):
        tree, altitudes = TestAttributes.get_test_tree()

        ref_attribute = [0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 8, 2, 8, 12, 27, 35.]
        attribute = hg.attribute_volume(tree, altitudes)

        self.assertTrue(np.allclose(ref_attribute, attribute))
Exemplo n.º 2
0
def watershed_hierarchy_by_volume(graph, edge_weights, vertex_area=None):
    """
    Watershed hierarchy by volume.

    The definition of hierarchical watershed follows the one given in:

        J. Cousty, L. Najman.
        `Incremental algorithm for hierarchical minimum spanning forests and saliency of watershed cuts <https://hal-upec-upem.archives-ouvertes.fr/hal-00622505/document>`_.
        ISMM 2011: 272-283.

    The algorithm used is described in:

        Laurent Najman, Jean Cousty, Benjamin Perret.
        `Playing with Kruskal: Algorithms for Morphological Trees in Edge-Weighted Graphs <https://hal.archives-ouvertes.fr/file/index/docid/798621/filename/ismm2013-algo.pdf>`_.
        ISMM 2013: 135-146.

    :param graph: input graph
    :param edge_weights: input graph edge weights
    :param vertex_area: area of the input graph vertices (provided by :func:`~higra.attribute_vertex_area`)
    :return: a tree (Concept :class:`~higra.CptHierarchy`) and its node altitudes
    """
    if vertex_area is None:
        vertex_area = hg.attribute_vertex_area(graph)

    vertex_area = hg.linearize_vertex_weights(vertex_area, graph)

    return watershed_hierarchy_by_attribute(
        graph, edge_weights, lambda tree, altitudes: hg.attribute_volume(
            tree, altitudes, hg.attribute_area(tree, vertex_area)))
Exemplo n.º 3
0
    def test_attribute_volume_with_area(self):
        tree = hg.Tree((5, 5, 6, 6, 6, 7, 7, 7))
        altitudes = np.asarray((0, 0, 0, 0, 0, 2, 1, 4.))
        area = np.asarray((2, 1, 1, 3, 2, 3, 6, 9))

        ref_attribute = [0, 0, 0, 0, 0, 6, 18, 24]
        attribute = hg.attribute_volume(tree, altitudes, area)

        self.assertTrue(np.allclose(ref_attribute, attribute))