MorphologicalAttributeFilters
Public API documentation
Loading...
Searching...
No Matches
MorphologicalTreeFactory.hpp
1#pragma once
2
3#include "MorphologicalTree.hpp"
4#include "TreeAltitudeAlgorithms.hpp"
5#include "WeightedMorphologicalTree.hpp"
6#include "detail/MorphologicalTreeConstructionTag.hpp"
7#include "sdrt/SelfDualResidualTreeBuilder.hpp"
8
9#include <optional>
10#include <span>
11#include <utility>
12
13namespace mmcfilters {
14
46private:
54 static constexpr detail::MorphologicalTreeConstructionTag tag() noexcept {
55 return detail::MorphologicalTreeConstructionTag{};
56 }
57
58public:
72 template<AltitudeValue T>
74 TreeAltitudeAlgorithms::validateFiniteImageAltitudes(img, "MorphologicalTreeFactory::createMaxTree image");
75 auto topology = MorphologicalTree(tag(), img, ComponentTreeKind::MAX_TREE, radius);
76 return WeightedMorphologicalTree<T>(tag(), std::move(topology), std::move(img));
77 }
78
92 template<AltitudeValue T>
94 TreeAltitudeAlgorithms::validateFiniteImageAltitudes(img, "MorphologicalTreeFactory::createMinTree image");
95 auto topology = MorphologicalTree(tag(), img, ComponentTreeKind::MIN_TREE, radius);
96 return WeightedMorphologicalTree<T>(tag(), std::move(topology), std::move(img));
97 }
98
123
150 template<AltitudeValue T>
151 [[nodiscard]] static WeightedMorphologicalTree<T> createFromHigraParent(std::span<const NodeId> higraParent, std::span<const T> higraAltitude, int rows, int cols, MorphologicalTreeKind kind, std::optional<AdjacencyRelation> adjacency = std::nullopt) {
152 auto topology = MorphologicalTree(tag(), higraParent, rows, cols, kind, std::move(adjacency));
153 return WeightedMorphologicalTree<T>(tag(), std::move(topology), detail::AltitudeInput<T>{higraAltitude, detail::AltitudeDomain::HigraNodeIds});
154 }
155
177 template<AltitudeValue T>
179 auto minTree = createMinTree(img, radius);
180 auto maxTree = createMaxTree(img, radius);
181 sdrt::SelfDualResidualTreeBuilder<T> builder(radius);
182 builder.build(img, std::move(minTree), std::move(maxTree));
183 auto topology = MorphologicalTree(tag(), builder.getNodeParent(), builder.getProperPartOwner(), builder.getRoot(), builder.getRows(), builder.getCols());
184 return WeightedMorphologicalTree<T>(tag(), std::move(topology), detail::AltitudeInput<T>{builder.getAltitude(), detail::AltitudeDomain::InternalNodeSlots});
185 }
186};
187
188} // namespace mmcfilters
std::shared_ptr< ImageUInt8 > ImageUInt8Ptr
Shared pointer to an 8-bit unsigned image.
Definition Image.hpp:243
Public construction facade for all high-level morphological trees.
static WeightedMorphologicalTree< std::uint8_t > createTreeOfShapes(ImageUInt8Ptr img, ToSInterpolation interpolation=ToSInterpolation::SelfDual, int infinitySeedRow=ToSDefaultInfinityRow, int infinitySeedCol=ToSDefaultInfinityCol)
Builds a weighted tree of shapes from an 8-bit image.
static WeightedMorphologicalTree< T > createMinTree(ImagePtr< T > img, double radius=1.5)
Builds a typed weighted min-tree from an image.
static WeightedMorphologicalTree< T > createMaxTree(ImagePtr< T > img, double radius=1.5)
Builds a typed weighted max-tree from an image.
static WeightedMorphologicalTree< T > createSelfDualResidualTree(ImagePtr< T > img, double radius=1.5)
Builds a typed weighted self-dual residual tree from an image.
static WeightedMorphologicalTree< T > createFromHigraParent(std::span< const NodeId > higraParent, std::span< const T > higraAltitude, int rows, int cols, MorphologicalTreeKind kind, std::optional< AdjacencyRelation > adjacency=std::nullopt)
Imports a static Higra parent/altitude hierarchy.
Mutable morphological tree built directly on proper parts and dense node ids.
static void validateFiniteImageAltitudes(const ImagePtr< T > &image, const char *context)
Rejects non-finite floating-point pixels before using an image as altitude source.
Owning result for one computed scalar attribute layout and buffer.