Alpha Tree
Include
<mln/morpho/alphatree.hpp>
-
auto alphatree(Image f, Neighborhood nbh, F dist);
Compute the alpha tree (also known as quasi-flat zone hierarchy) and returns a pair (tree, node_map). See Component Trees (Overview) for more information about the representation of tree. The implementation is based on the Kruskal algorithm [Naj13].
- Parameters:
input – The input image
nbh – The neighborhood
dist – The function weighting the edges between two pixels. For grayscale images, this is generally the absolute difference between two values.
- Returns:
A pair (tree, node_map) where tree is of type
component_tree<std::invoke_result_t<F, image_value_t<Image>, image_value_t<Image>>>
and node_map is a mapping between the image pixels and the node of the tree.
Requirements
std::invoke_result_t<F, image_value_t<Image>, image_value_t<Image>>
isstd::totally_ordered
Definition
The Alpha tree is the tree of \(\alpha\)-connected components. An \(\alpha\)-connected component in an image \(f\), for a pixel \(p\), is defined as
where \(d\) is a dissimilarity function between two pixels of the image \(f\).
The \(\alpha\)-connected components form an ordered sequence when \(\alpha\) is growing, such that for \(\alpha_i < \alpha_j\), \(\alpha_i-CC(p) \subseteq \alpha_j-CC(p)\). Thus, the alphatree is the hierarchy where the parenthood relationship represents the inclusion of the \(\alpha\)-connected components.
Representation
The alphatree
function returns a tree and a node map. The tree has two attributes:
parent
: The parenthood relationship of the node \(i\), representing the inclusion relationship of the \(\alpha\)-connected components.values
: The value of \(\alpha\) assigned to a node \(i\).
Then, the node map is the relation between a pixel of the image and its related node in the tree, a leaf for the case of the alphatree.
The image above illustrates the representation of the alpha tree in Pylene, the parenthood relationship being illustrated in arrows, the values of alpha, assigned to each node, being in red, and the relation between a node of the tree and a pixel of the image being represented by blue dashed lines.
Example
This example is used to generate the grayscale lena cut with a threshold of 3 below.
#include <mln/accu/accumulators/mean.hpp> #include <mln/morpho/alphatree.hpp> #include <mln/core/image/ndimage.hpp> #include <mln/core/neighborhood/c4.hpp> mln::image2d<uint8_t> input = ...; // Compute the alpha tree auto [tree, node_map] = mln::morpho::alphatree(input, mln::c4); // Compute an attribute (for example the average pixels value at each node, as below) auto mean = t.compute_attribute_on_values(node_map, input, mln::accu::accumulators::mean<uint8_t>()); // Making an horizontal cut of the tree const auto threshold = 3; // Threshold of the horizontal cut, that means the lowest alpha in the cut auto nodemap_cut = t.horizontal_cut(threshold, node_map); // Return a new nodemap associated to the cut // Labelizing the cut with the mean values of each node auto out = t.reconstruct_from(nodemap_cut, ranges::make_span(mean)); // Using range-v3 span
Notes
Complexity
References
Laurent Najman, Jean Cousty, and Benjamin Perret (2013). Playing with kruskal: algorithms for morphological trees in edge-weighted graphs. International Symposium on Mathematical Morphology and Its Applications to Signal and Image Processing. Springer, Berlin, Heidelberg. 135-146