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/TreeKernelAccess.hpp"
9#include "../utils/CommittedImageAccess.hpp"
10#include "../utils/Contract.hpp"
11#include "AttributeReconstructionFilters.hpp"
12#include "detail/ViterbiDecision.hpp"
106 throw std::invalid_argument(std::string(
context) +
" requires a non-null attribute buffer."));
119 throw std::invalid_argument(std::string(
context) +
120 " node-preservation-mask size must match the internal node slot count."));
133 throw std::invalid_argument(std::string(
context) +
" output image shape must match the tree image domain."));
143 static T
altitudeOf(
const AltitudeView& view,
NodeId nodeId)
noexcept {
return view.nodeAltitudes()[
static_cast<std::size_t
>(nodeId)]; }
157 for (
PixelId pixel : detail::TreeKernelAccess::properParts(tree, nodeId)) {
194 const char*
context =
"AttributeFilters::filteringByPruningMin";
195 view.requireTopologyUnchanged(
context);
199 std::stack<NodeId>
stack;
203 while (!
stack.empty()) {
231 const char*
context =
"AttributeFilters::filteringByPruningMax";
232 view.requireTopologyUnchanged(
context);
240 detail::TreeKernelAccess::traversePostOrder(
243 collapsibleRejectedSubtree[nodeId] = !nodePreservationMask[static_cast<std::size_t>(nodeId)];
246 collapsibleRejectedSubtree[parentNodeId] =
247 (collapsibleRejectedSubtree[parentNodeId] & collapsibleRejectedSubtree[childNodeId]);
252 std::stack<NodeId>
stack;
254 while (!
stack.empty()) {
282 template <std::
floating_po
int Real>
284 const char*
context =
"AttributeFilters::filteringByPruningMin";
285 view.requireTopologyUnchanged(
context);
290 std::stack<NodeId>
stack;
292 while (!
stack.empty()) {
319 template <std::
floating_po
int Real>
321 const char*
context =
"AttributeFilters::filteringByPruningMax";
322 view.requireTopologyUnchanged(
context);
330 detail::TreeKernelAccess::traversePostOrder(
333 if (attribute[nodeId] <= threshold) {
334 collapsibleRejectedSubtree[nodeId] = true;
344 std::stack<NodeId>
stack;
346 while (!
stack.empty()) {
465 requireStableTree(
"AttributeFilters::filteringByViterbiRule");
558 template <std::
floating_po
int Real>
572 template <std::
floating_po
int Real>
587 template <std::
floating_po
int Real>
601 template <std::
floating_po
int Real>
615 template <std::
floating_po
int Real>
629 template <std::
floating_po
int Real>
644 template <std::
floating_po
int Real>
658 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.