3#include "../utils/Image.hpp"
4#include "../utils/Common.hpp"
5#include "../trees/TreeAltitudeAlgorithms.hpp"
6#include "../trees/ValuedMorphologicalTree.hpp"
7#include "../trees/ValuedMorphologicalTreeView.hpp"
8#include "../trees/detail/CommittedTreeAccess.hpp"
9#include "../trees/detail/TreeTraversalDetail.hpp"
10#include "../utils/CommittedImageAccess.hpp"
11#include "../utils/Contract.hpp"
12#include "AttributeReconstructionFilters.hpp"
13#include "detail/ViterbiDecision.hpp"
107 throw std::invalid_argument(std::string(
context) +
" requires a non-null attribute buffer."));
120 throw std::invalid_argument(std::string(
context) +
121 " node-preservation-mask size must match the internal node slot count."));
134 throw std::invalid_argument(std::string(
context) +
" output image shape must match the tree image domain."));
158 for (
PixelId pixel : detail::CommittedTreeAccess::properParts(tree,
nodeId)) {
195 const char*
context =
"AttributeFilters::filteringByPruningMin";
196 view.requireTopologyUnchanged(
context);
200 std::stack<NodeId>
stack;
204 while (!
stack.empty()) {
232 const char*
context =
"AttributeFilters::filteringByPruningMax";
233 view.requireTopologyUnchanged(
context);
241 detail::traversePostOrder(
244 collapsibleRejectedSubtree[nodeId] = !nodePreservationMask[static_cast<std::size_t>(nodeId)];
247 collapsibleRejectedSubtree[parentNodeId] =
248 (collapsibleRejectedSubtree[parentNodeId] & collapsibleRejectedSubtree[childNodeId]);
253 std::stack<NodeId>
stack;
255 while (!
stack.empty()) {
283 template <std::
floating_po
int Real>
285 const char*
context =
"AttributeFilters::filteringByPruningMin";
286 view.requireTopologyUnchanged(
context);
291 std::stack<NodeId>
stack;
293 while (!
stack.empty()) {
320 template <std::
floating_po
int Real>
322 const char*
context =
"AttributeFilters::filteringByPruningMax";
323 view.requireTopologyUnchanged(
context);
331 detail::traversePostOrder(
334 if (attribute[nodeId] <= threshold) {
335 collapsibleRejectedSubtree[nodeId] = true;
345 std::stack<NodeId>
stack;
347 while (!
stack.empty()) {
466 requireStableTree(
"AttributeFilters::filteringByViterbiRule");
559 template <std::
floating_po
int Real>
573 template <std::
floating_po
int Real>
588 template <std::
floating_po
int Real>
602 template <std::
floating_po
int Real>
616 template <std::
floating_po
int Real>
630 template <std::
floating_po
int Real>
645 template <std::
floating_po
int Real>
659 template <std::
floating_po
int Real>
#define MMCFILTERS_CONTRACT_REQUIRE(condition,...)
Evaluates a caller precondition and its failure action only in checked builds.
#define MMCFILTERS_CONTRACT_CHECKED_ONLY(...)
Executes validation statements only when defensive checks are enabled.
Family of attribute-based image filtering operators on morphological trees.
AttributeFilters(const ValuedMorphologicalTree< T > &valuedTree)
Creates filtering operators over an owned valued tree.
static void filteringByPruningMin(const ValuedMorphologicalTree< T > &valuedTree, const std::shared_ptr< Real[]> &attribute, Real threshold, ImagePtr< T > imgOutputPtr)
Writes pruning-min filtering from a valued-tree owner and owned attribute buffer.
static void filteringByPruningMin(const ValuedMorphologicalTreeView< T > &valuedTree, const std::shared_ptr< Real[]> &attribute, Real threshold, ImagePtr< T > imgOutputPtr)
Writes pruning-min filtering from an owned attribute buffer into an output image.
static void filteringByPruningMax(const ValuedMorphologicalTree< T > &valuedTree, const Real *attribute, Real threshold, ImagePtr< T > imgOutputPtr)
Writes pruning-max filtering from a valued-tree owner and raw attribute buffer.
static void filteringByPruningMin(const ValuedMorphologicalTreeView< T > &valuedTree, const NodePreservationMask &nodePreservationMask, ImagePtr< T > imgOutputPtr)
Writes pruning-min filtering from a node-preservation mask into an output image.
static void filteringByPruningMin(const ValuedMorphologicalTree< T > &valuedTree, const NodePreservationMask &nodePreservationMask, ImagePtr< T > imgOutputPtr)
Writes pruning-min filtering from a valued-tree owner into an output image.
static void filteringByPruningMin(const ValuedMorphologicalTree< T > &valuedTree, const Real *attribute, Real threshold, ImagePtr< T > imgOutputPtr)
Writes pruning-min filtering from a valued-tree owner and raw attribute buffer.
static void filteringByPruningMax(const ValuedMorphologicalTree< T > &valuedTree, const std::shared_ptr< Real[]> &attribute, Real threshold, ImagePtr< T > imgOutputPtr)
Writes pruning-max filtering from a valued-tree owner and owned attribute buffer.
ImagePtr< T > filteringByPruningMin(const NodePreservationMask &nodePreservationMask)
Applies pruning-min filtering from a dense node-preservation mask.
static void filteringByPruningMax(const ValuedMorphologicalTreeView< T > &valuedTree, const NodePreservationMask &nodePreservationMask, ImagePtr< T > imgOutputPtr)
Writes pruning-max filtering from a node-preservation mask into an output image.
static void filteringByPruningMax(const ValuedMorphologicalTree< T > &valuedTree, const NodePreservationMask &nodePreservationMask, ImagePtr< T > imgOutputPtr)
Writes pruning-max filtering from a valued-tree owner into an output image.
ImagePtr< T > filteringByViterbiRule(const Real *attr, Real threshold)
Applies Salembier-style Viterbi filtering from a raw attribute buffer.
~AttributeFilters()=default
Destroys the attribute-filter facade.
AttributeFilters(AltitudeView view)
Creates filtering operators over a non-owning valued tree view.
static void filteringByPruningMin(const ValuedMorphologicalTreeView< T > &valuedTree, const Real *attribute, Real threshold, ImagePtr< T > imgOutputPtr)
Writes pruning-min filtering from a raw attribute buffer into an output image.
static void filteringByPruningMax(const ValuedMorphologicalTreeView< T > &valuedTree, const std::shared_ptr< Real[]> &attribute, Real threshold, ImagePtr< T > imgOutputPtr)
Writes pruning-max filtering from an owned attribute buffer into an output image.
ImagePtr< T > filteringByPruningMin(const std::shared_ptr< Real[]> &attr, Real threshold)
Applies pruning-min filtering from an attribute buffer.
ImagePtr< T > filteringByPruningMax(const Real *attr, Real threshold)
Applies pruning-max filtering from a raw internal-node attribute buffer.
static void filteringByPruningMax(const ValuedMorphologicalTreeView< T > &valuedTree, const Real *attribute, Real threshold, ImagePtr< T > imgOutputPtr)
Writes pruning-max filtering from a raw attribute buffer into an output image.
ImagePtr< T > filteringByPruningMax(const NodePreservationMask &nodePreservationMask)
Applies pruning-max filtering from a dense node-preservation mask.
ImagePtr< T > filteringByPruningMin(const Real *attr, Real threshold)
Applies pruning-min filtering from a raw internal-node attribute buffer.
ImagePtr< T > filteringByPruningMax(const std::shared_ptr< Real[]> &attr, Real threshold)
Applies pruning-max filtering from an attribute buffer.
static Ptr create(int rows, int columns)
Creates an owned image with uninitialised pixel values.
Mutable connected-subset tree on a finite pixel domain.
int numRows() const
Returns the number of rows in the regular 2D pixel domain.
int numInternalNodeSlots() const
Returns the size of the dense internal-node id domain.
void requireMutationVersion(std::size_t expectedVersion, const char *context) const
Rejects stale read-only views that captured an older mutation version.
int numColumns() const
Returns the number of columns in the regular 2D pixel domain.
NodeId root() const
Returns the current hierarchy root.
Dense Boolean decisions where true means preserve the node.
Owning result for one computed scalar attribute layout and buffer.