3#include "../attributes/AttributeComputation.hpp"
4#include "../trees/detail/TreeStabilityNeighborhood.hpp"
5#include "../trees/detail/TreeKindValidation.hpp"
6#include "../trees/MorphologicalTree.hpp"
7#include "../trees/TreeAltitudeAlgorithms.hpp"
8#include "../trees/WeightedMorphologicalTree.hpp"
9#include "../utils/Common.hpp"
10#include "detail/VariationMeasure.hpp"
55template<AltitudeValue T, std::
floating_po
int Real =
float>
64 const std::vector<T>& altitude_;
65 const Real* attrMserView_;
66 std::vector<Real> ownedAttrMser_;
71 std::vector<Real> variation;
72 std::vector<NodeId> ascendants;
73 std::vector<NodeId> descendants;
75 static void validateOwnedAttributeSize(
const MorphologicalTree& tree,
const std::vector<Real>& attr) {
77 throw std::invalid_argument(
"MSERComputer attribute size must match the internal node slot count.");
84 altitude_(
weighted.getAltitudeBuffer()),
87 maxVariation(
Real{10}),
91 detail::validateComponentTreeKind(this->tree,
"MSERComputer");
92 this->attrMserView_ = this->ownedAttrMser_.empty() ?
attr_increasing : this->ownedAttrMser_.data();
113 throw std::invalid_argument(
"MSERComputer requires a non-null attribute buffer for the raw-pointer constructor.");
123 ~MSERComputer() =
default;
133 detail::computeAltitudeStabilityNeighborhood(
135 std::span<const T>(altitude_),
138 this->descendants = std::move(
neighborhood.descendants);
144 detail::computeVariationsFromNeighborhood<Real>(
149 return detail::selectStrictVariationMinima<Real>(
166 detail::validateStabilityNeighborhoodShape(
170 "MSERComputer::getVariation");
171 if (this->variation.size() !=
static_cast<std::size_t
>(
this->tree.getNumInternalNodeSlots())) {
172 throw std::logic_error(
"MSERComputer::getVariation requires computeMSER to run first.");
177 return detail::computeVariationValue<Real>(
189 if(attrMserView_ ==
nullptr) {
190 auto area = AttributeComputation::computeSingleAttribute<Real>(weighted_, AREA);
192 attrMserView_ = ownedAttrMser_.data();
194 if(attrMserView_ ==
nullptr)
197 return this->attrMserView_[node];
205 detail::validateStabilityNeighborhoodShape(
209 "MSERComputer::nodeWithMinimumVariationInWindow");
210 if (this->variation.size() !=
static_cast<std::size_t
>(
this->tree.getNumInternalNodeSlots())) {
211 throw std::logic_error(
"MSERComputer::nodeWithMinimumVariationInWindow requires computeMSER to run first.");
213 return detail::nodeWithMinimumVariationInWindow<Real>(
int NodeId
Node identifier type used throughout the project.
Detects MSER-like nodes from a monotone increasing attribute defined on the hierarchy.
MSERComputer(const WeightedMorphologicalTree< T > &weighted)
Creates an MSER detector that lazily falls back to AREA.
int getNumNodes()
Returns the number of nodes selected as MSER-like in the last run.
MSERComputer(const WeightedMorphologicalTree< T > &weighted, const Real *attr_increasing)
Creates an MSER detector backed by a non-owning attribute view.
Real getVariation(NodeId node)
Returns the variation score currently associated with a node.
std::vector< uint8_t > computeMSER(AltitudeDiff< T > delta)
Computes the MSER indicator vector for the given delta.
NodeId descendantInStabilityWindow(NodeId node) const
Returns the descendant used in the current stability window.
MSERComputer(const WeightedMorphologicalTree< T > &weighted, std::vector< Real > attr_increasing)
Creates an MSER detector backed by an owned attribute buffer.
NodeId nodeWithMinimumVariationInWindow(NodeId node)
Returns the node with minimum variation among the current node and its delta-linked neighbours.
void setMaxVariation(Real maxVariation)
Sets the maximum accepted variation value.
void setMaxAttribute(Real maxAttr)
Sets the upper bound of the accepted attribute interval.
NodeId ascendantInStabilityWindow(NodeId node) const
Returns the ascendant used in the current stability window.
std::vector< Real > & getVariations()
Returns the current variation array, indexed by node slot.
void setMinAttribute(Real minAttr)
Sets the lower bound of the accepted attribute interval.
Real getAttrMSER(NodeId node)
Returns the attribute used by the MSER criterion, lazily computing AREA when no external buffer has b...
Mutable morphological tree built directly on proper parts and dense node ids.
int getNumInternalNodeSlots() const
Returns the size of the dense internal-node id domain.
static void validateAltitudeBufferShape(const MorphologicalTree &tree, std::span< const T > altitude)
Validates that an altitude buffer covers the dense internal-node domain.
Owning result for one computed scalar attribute layout and buffer.
std::vector< Real > second
Flat per-node attribute buffer indexed through first.