Volume Cartographer 2.28.0
OpticalFlowSegmentation.hpp
Go to the documentation of this file.
1#pragma once
2
5#include <cstddef>
6#include <cstdint>
7#include <optional>
8
13
15{
33{
34public:
36 using Pointer = std::shared_ptr<OpticalFlowSegmentation>;
37
40
42 ~OpticalFlowSegmentation() override = default;
43
45 template <typename... Args>
46 static auto New(Args... args) -> Pointer
47 {
48 return std::make_shared<OpticalFlowSegmentation>(
49 std::forward<Args>(args)...);
50 }
51
53 void setStartZIndex(int z);
54
56 [[nodiscard]] auto getStartZIndex() const -> int;
57
59 void setTargetZIndex(int z);
60
62 [[nodiscard]] auto getTargetZIndex() const -> int;
63
68 void setOutsideThreshold(std::uint8_t outside);
69
75 void setOFThreshold(std::uint8_t ofThr);
76
81 void setOFDispThreshold(std::uint32_t ofDispThrs);
82
89 void setSmoothBrightnessThreshold(std::uint8_t brightness);
90
92 void setEnableSmoothOutliers(bool enable);
93
95 void setEnableEdgeDetection(bool enable);
96
98 void setEdgeJumpDistance(std::uint32_t distance);
99
101 void setEdgeBounceDistance(std::uint32_t distance);
102
104 void setInterpolate(bool b);
105
108 void setInterpolationWindow(std::uint32_t window);
109
112 [[nodiscard]] auto getInterpolationWindow() const -> std::uint32_t;
113
117 void setInterpolationDistance(std::uint32_t distance);
118
122 [[nodiscard]] auto getInterpolationDistance() const -> std::uint32_t;
123
127 void setMasterCloud(PointSet masterCloud);
128
131
137 void setMaterialThickness(double m);
138
140 void setMaxThreads(std::uint32_t t);
141
144
146 void setVisualize(bool b);
147
149 void setDumpVis(bool b);
150
152 auto compute() -> PointSet override;
153
155 [[nodiscard]] auto progressIterations() const -> std::size_t override;
156
157private:
162 [[nodiscard]] auto compute_curve_(
163 const FittedCurve& currentCurve, int zIndex) const
164 -> std::vector<Voxel>;
165
175 int interpStart, int interpEnd, int startChain, int startResegChain)
176 -> std::vector<std::vector<Voxel>>;
177
190 Chain currentVs,
191 int startChainIndex,
192 int anchorEndIdx,
193 int targetIndex,
194 int stepAdjustment,
195 std::size_t& iteration,
196 bool backwards,
197 const filesystem::path& debugDir)
198 -> std::tuple<std::vector<std::vector<Voxel>>, Status>;
199
203 int endIndex_{0};
210 std::uint8_t outsideThreshold_{80};
235 std::uint8_t smoothByBrightness_{180};
239 bool enableEdge_{false};
241 std::uint32_t edgeJumpDistance_{6};
243 std::uint32_t edgeBounceDistance_{3};
245 bool requestInterp_{false};
247 std::uint32_t interpWindow_{5};
249 std::uint32_t interpDist_{25};
257 std::optional<std::uint32_t> maxThreads_;
259 bool dumpVis_{false};
261 bool visualize_{false};
262};
263} // namespace volcart::segmentation
Base class for segmentation algorithms that propagate a collected chain of points.
std::shared_ptr< ChainSegmentationAlgorithm > Pointer
Fits a curve to a set of points for resampling.
Definition: FittedCurve.hpp:19
void setOFDispThreshold(std::uint32_t ofDispThrs)
Set the maximum single pixel optical flow displacement before interpolating a pixel region.
void setTargetZIndex(int z)
Set the target z-index.
void setMaterialThickness(double m)
Set the estimated thickness of the substrate (in um)
auto run_ofs_(Chain currentVs, int startChainIndex, int anchorEndIdx, int targetIndex, int stepAdjustment, std::size_t &iteration, bool backwards, const filesystem::path &debugDir) -> std::tuple< std::vector< std::vector< Voxel > >, Status >
Run the optical flow segmentation in one direction.
auto getInterpolationWindow() const -> std::uint32_t
Get how wide the interpolation window should be.
void setEdgeJumpDistance(std::uint32_t distance)
Set the minimum jump distance for edge detection.
OpticalFlowSegmentation()=default
Default constructor.
auto interpolate_(int interpStart, int interpEnd, int startChain, int startResegChain) -> std::vector< std::vector< Voxel > >
Blend the re-segmentation run into the forward run over an interpolation window.
auto compute() -> PointSet override
Compute the segmentation.
void setEdgeBounceDistance(std::uint32_t distance)
Set the maximum bounce distance for edge detection.
void resetMaxThreads()
Clear the maximum number of threads.
void setReSegmentationChain(Chain c)
Set the input chain of re-segmentation points.
auto compute_curve_(const FittedCurve &currentCurve, int zIndex) const -> std::vector< Voxel >
Compute the curve for z + 1 given a curve on z using the optical flow between the two slices.
void setMaxThreads(std::uint32_t t)
Set the maximum number of threads.
void setEnableEdgeDetection(bool enable)
Set whether to enable edge detection.
void setEnableSmoothOutliers(bool enable)
Set whether to enable outlier points smoothening.
auto getStartZIndex() const -> int
Get the start z-index.
void setStartZIndex(int z)
Set the start z-index.
void setOutsideThreshold(std::uint8_t outside)
Set the threshold of what pixel brightness is considered inside a sheet (higher as threshold) and out...
void setSmoothBrightnessThreshold(std::uint8_t brightness)
Set the threshold for what pixel brightness is considered as being outside the sheet....
void setMasterCloud(PointSet masterCloud)
Set the already computed masterCloud OrderedPointSet.
void setOFThreshold(std::uint8_t ofThr)
Set the threshold of what pixel brightness is considered while calculating optical flow,...
void setInterpolate(bool b)
Set whether to interpolate against the master cloud.
void setInterpolationDistance(std::uint32_t distance)
Set how many slices the interpolation center is away from the start slice.
auto progressIterations() const -> std::size_t override
Returns the maximum progress value.
auto getTargetZIndex() const -> int
Get the target z-index.
auto getInterpolationDistance() const -> std::uint32_t
Get how many slices the interpolation center is away from the start slice.
void setInterpolationWindow(std::uint32_t window)
Set how wide the interpolation window should be.
Segmentation algorithms and utilities library