Volume Cartographer 2.28.0
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
volcart::segmentation::OpticalFlowSegmentation Class Reference

Optical Flow Segmentation. More...

#include <vc/segmentation/OpticalFlowSegmentation.hpp>

Inheritance diagram for volcart::segmentation::OpticalFlowSegmentation:
[legend]
Collaboration diagram for volcart::segmentation::OpticalFlowSegmentation:
[legend]

Public Types

using Pointer = std::shared_ptr< OpticalFlowSegmentation >
 
- Public Types inherited from volcart::segmentation::ChainSegmentationAlgorithm
enum class  Status { Success , Failure , ReturnedEarly }
 
using Pointer = std::shared_ptr< ChainSegmentationAlgorithm >
 
using Chain = std::vector< cv::Vec3d >
 
using PointSet = OrderedPointSet< cv::Vec3d >
 
using Bounds = BoundingBox< double, 3 >
 

Public Member Functions

 OpticalFlowSegmentation ()=default
 Default constructor.
 
 ~OpticalFlowSegmentation () override=default
 
void setStartZIndex (int z)
 Set the start z-index.
 
auto getStartZIndex () const -> int
 Get the start z-index.
 
void setTargetZIndex (int z)
 Set the target z-index.
 
auto getTargetZIndex () const -> int
 Get the target z-index.
 
void setOutsideThreshold (std::uint8_t outside)
 Set the threshold of what pixel brightness is considered inside a sheet (higher as threshold) and outside (lower as threshold)
 
void setOFThreshold (std::uint8_t ofThr)
 Set the threshold of what pixel brightness is considered while calculating optical flow, darker pixels OF is interpolated from brighter ones in the area.
 
void setOFDispThreshold (std::uint32_t ofDispThrs)
 Set the maximum single pixel optical flow displacement before interpolating a pixel region.
 
void setSmoothBrightnessThreshold (std::uint8_t brightness)
 Set the threshold for what pixel brightness is considered as being outside the sheet. Pixels above this threshold are considered outside the sheet and are smoothed in an attempt to get them tracking the sheet again.
 
void setEnableSmoothOutliers (bool enable)
 Set whether to enable outlier points smoothening.
 
void setEnableEdgeDetection (bool enable)
 Set whether to enable edge detection.
 
void setEdgeJumpDistance (std::uint32_t distance)
 Set the minimum jump distance for edge detection.
 
void setEdgeBounceDistance (std::uint32_t distance)
 Set the maximum bounce distance for edge detection.
 
void setInterpolate (bool b)
 Set whether to interpolate against the master cloud.
 
void setInterpolationWindow (std::uint32_t window)
 Set how wide the interpolation window should be.
 
auto getInterpolationWindow () const -> std::uint32_t
 Get how wide the interpolation window should be.
 
void setInterpolationDistance (std::uint32_t distance)
 Set how many slices the interpolation center is away from the start slice.
 
auto getInterpolationDistance () const -> std::uint32_t
 Get how many slices the interpolation center is away from the start slice.
 
void setMasterCloud (PointSet masterCloud)
 Set the already computed masterCloud OrderedPointSet.
 
void setReSegmentationChain (Chain c)
 Set the input chain of re-segmentation points.
 
void setMaterialThickness (double m)
 Set the estimated thickness of the substrate (in um) More...
 
void setMaxThreads (std::uint32_t t)
 Set the maximum number of threads.
 
void resetMaxThreads ()
 Clear the maximum number of threads.
 
void setVisualize (bool b)
 
void setDumpVis (bool b)
 
auto compute () -> PointSet override
 Compute the segmentation. More...
 
auto progressIterations () const -> std::size_t override
 Returns the maximum progress value. More...
 
- Public Member Functions inherited from volcart::segmentation::ChainSegmentationAlgorithm
 ~ChainSegmentationAlgorithm () override=default
 
auto progressIterations () const -> std::size_t override
 Returns the maximum progress value. More...
 
void setVolume (Volume::Pointer vol)
 Set the input Volume. More...
 
void setBounds (Bounds b)
 Set the bounding box for computation. More...
 
void setChain (Chain c)
 Set the input chain of seed points. More...
 
void setNumberOfSteps (std::size_t n)
 Set the number of propagation steps. More...
 
void setStepSize (double s)
 Set the propagation step size. More...
 
auto getStatus () const -> Status
 Get the status of the previous computation. More...
 
auto getPointSet () const -> const PointSet &
 Get the segmented pointset. More...
 
auto getPointSet () -> PointSet &
 Get the segmented pointset. More...
 
virtual std::size_t progressIterations () const =0
 

Static Public Member Functions

template<typename... Args>
static auto New (Args... args) -> Pointer
 

Private Member Functions

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.
 
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. More...
 
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. More...
 

Private Attributes

int startIndex_ {0}
 
int endIndex_ {0}
 
std::uint8_t outsideThreshold_ {80}
 
std::uint8_t opticalFlowPixelThreshold_ {80}
 
std::uint32_t opticalFlowDisplacementThreshold_ {10}
 
std::uint8_t smoothByBrightness_ {180}
 
bool enableSmoothenOutlier_ {true}
 
bool enableEdge_ {false}
 
std::uint32_t edgeJumpDistance_ {6}
 
std::uint32_t edgeBounceDistance_ {3}
 
bool requestInterp_ {false}
 
std::uint32_t interpWindow_ {5}
 
std::uint32_t interpDist_ {25}
 
Chain resegStartingChain_
 
PointSet masterCloud_
 
double materialThickness_ {100}
 
std::optional< std::uint32_t > maxThreads_
 
bool dumpVis_ {false}
 
bool visualize_ {false}
 

Additional Inherited Members

- Public Attributes inherited from volcart::IterationsProgress
Signal progressStarted
 
Signal< std::size_t > progressUpdated
 
Signal progressComplete
 
- Protected Member Functions inherited from volcart::segmentation::ChainSegmentationAlgorithm
 ChainSegmentationAlgorithm ()=default
 
- Protected Attributes inherited from volcart::segmentation::ChainSegmentationAlgorithm
Volume::Pointer vol_
 
Chain startingChain_
 
Bounds bb_
 
std::size_t numSteps_ {0}
 
double stepSize_ {1.0}
 
PointSet result_
 
Status status_ {Status::Success}
 

Detailed Description

Optical Flow Segmentation.

Author
Julian Schilliger
Date
May 2023

This algorithm propagates a chain of points forward through a volume from a starting z-index to an ending z-index (inclusive). It uses optical flow to track the shape of the layer. Each seed point is assumed to be placed within the layer rather than on its surface boundary.

Warning
This algorithm is non-deterministic and yields slightly different results each run.

Definition at line 32 of file OpticalFlowSegmentation.hpp.

Member Typedef Documentation

◆ Pointer

Pointer

Definition at line 36 of file OpticalFlowSegmentation.hpp.

Constructor & Destructor Documentation

◆ ~OpticalFlowSegmentation()

volcart::segmentation::OpticalFlowSegmentation::~OpticalFlowSegmentation ( )
overridedefault

Default destructor

Member Function Documentation

◆ compute()

auto volcart::segmentation::OpticalFlowSegmentation::compute ( ) -> PointSet
overridevirtual

Compute the segmentation.

Implements volcart::segmentation::ChainSegmentationAlgorithm.

◆ interpolate_()

auto volcart::segmentation::OpticalFlowSegmentation::interpolate_ ( int  interpStart,
int  interpEnd,
int  startChain,
int  startResegChain 
) -> std::vector< std::vector< Voxel > >
private

Blend the re-segmentation run into the forward run over an interpolation window.

Parameters
interpStartFirst z-slice of the interpolation window
interpEndLast z-slice of the interpolation window
startChainZ-index of the primary starting chain
startResegChainZ-index of the re-segmentation starting chain

◆ New()

template<typename... Args>
static auto volcart::segmentation::OpticalFlowSegmentation::New ( Args...  args) -> Pointer
inlinestatic

Make a new shared instance

Definition at line 46 of file OpticalFlowSegmentation.hpp.

◆ progressIterations()

auto volcart::segmentation::OpticalFlowSegmentation::progressIterations ( ) const -> std::size_t
overridevirtual

Returns the maximum progress value.

Reimplemented from volcart::segmentation::ChainSegmentationAlgorithm.

◆ run_ofs_()

auto volcart::segmentation::OpticalFlowSegmentation::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 >
private

Run the optical flow segmentation in one direction.

Parameters
currentVsStarting chain of points
startChainIndexZ-index of the starting chain
anchorEndIdxZ-index at which to stop and return
targetIndexFinal target z-index (used for bounds checking)
stepAdjustmentInitial step offset to align with the grid
iterationRunning progress counter (updated in place)
backwardsTrue to propagate toward lower z-indices
debugDirRoot directory for debug visualizations

◆ setDumpVis()

void volcart::segmentation::OpticalFlowSegmentation::setDumpVis ( bool  b)

Debug: Dumps reslices and intensity maps to disk

◆ setMaterialThickness()

void volcart::segmentation::OpticalFlowSegmentation::setMaterialThickness ( double  m)

Set the estimated thickness of the substrate (in um)

Used to generate the radius of the structure tensor calculation

◆ setVisualize()

void volcart::segmentation::OpticalFlowSegmentation::setVisualize ( bool  b)

Debug: Shows intensity maps in GUI window

Member Data Documentation

◆ dumpVis_

bool volcart::segmentation::OpticalFlowSegmentation::dumpVis_ {false}
private

Dump visualization to disk flag

Definition at line 259 of file OpticalFlowSegmentation.hpp.

◆ edgeBounceDistance_

std::uint32_t volcart::segmentation::OpticalFlowSegmentation::edgeBounceDistance_ {3}
private

Maximum displacement (voxels) allowed as a bounce from an edge

Definition at line 243 of file OpticalFlowSegmentation.hpp.

◆ edgeJumpDistance_

std::uint32_t volcart::segmentation::OpticalFlowSegmentation::edgeJumpDistance_ {6}
private

Minimum displacement (voxels) considered an edge jump

Definition at line 241 of file OpticalFlowSegmentation.hpp.

◆ enableEdge_

bool volcart::segmentation::OpticalFlowSegmentation::enableEdge_ {false}
private

Enable edge detection to constrain point movement

Definition at line 239 of file OpticalFlowSegmentation.hpp.

◆ enableSmoothenOutlier_

bool volcart::segmentation::OpticalFlowSegmentation::enableSmoothenOutlier_ {true}
private

Enable smoothing of detected outlier points

Definition at line 237 of file OpticalFlowSegmentation.hpp.

◆ endIndex_

int volcart::segmentation::OpticalFlowSegmentation::endIndex_ {0}
private

Target z-index

Definition at line 203 of file OpticalFlowSegmentation.hpp.

◆ interpDist_

std::uint32_t volcart::segmentation::OpticalFlowSegmentation::interpDist_ {25}
private

Distance in slices from the start slice to the interpolation center

Definition at line 249 of file OpticalFlowSegmentation.hpp.

◆ interpWindow_

std::uint32_t volcart::segmentation::OpticalFlowSegmentation::interpWindow_ {5}
private

Half-width of the interpolation window in slices (must be positive)

Definition at line 247 of file OpticalFlowSegmentation.hpp.

◆ masterCloud_

PointSet volcart::segmentation::OpticalFlowSegmentation::masterCloud_
private

Pre-computed master cloud used for interpolation blending

Definition at line 253 of file OpticalFlowSegmentation.hpp.

◆ materialThickness_

double volcart::segmentation::OpticalFlowSegmentation::materialThickness_ {100}
private

Estimated material thickness in um

Definition at line 255 of file OpticalFlowSegmentation.hpp.

◆ maxThreads_

std::optional<std::uint32_t> volcart::segmentation::OpticalFlowSegmentation::maxThreads_
private

Maximum number of threads

Definition at line 257 of file OpticalFlowSegmentation.hpp.

◆ opticalFlowDisplacementThreshold_

std::uint32_t volcart::segmentation::OpticalFlowSegmentation::opticalFlowDisplacementThreshold_ {10}
private

Threshold of how many pixels optical flow can displace a point, if higher, recompute optical flow with region's average flow. This parameter sets the maximum single pixel optical flow displacement before interpolating a pixel region. Range minimum: 0. Higher values allow more displacement before interpolation, while lower values trigger interpolation more frequently.

Definition at line 228 of file OpticalFlowSegmentation.hpp.

◆ opticalFlowPixelThreshold_

std::uint8_t volcart::segmentation::OpticalFlowSegmentation::opticalFlowPixelThreshold_ {80}
private

Disregarding pixel that are darker during optical flow computation. This parameter sets the threshold for what pixel brightness is considered while calculating optical flow. Darker pixels' optical flow is interpolated from brighter ones in the area. Range: 0-255. Higher values disregard more dark pixels during computation, while lower values include more dark pixels.

Definition at line 219 of file OpticalFlowSegmentation.hpp.

◆ outsideThreshold_

std::uint8_t volcart::segmentation::OpticalFlowSegmentation::outsideThreshold_ {80}
private

Darker pixels are considered outside the sheet. This parameter sets the threshold of what pixel brightness is considered too deep inside a sheet (higher than the threshold) and then tries to smoothen those points back towards the edge of the sheet. Range: 0-255.

Definition at line 210 of file OpticalFlowSegmentation.hpp.

◆ requestInterp_

bool volcart::segmentation::OpticalFlowSegmentation::requestInterp_ {false}
private

Enable blending of OFS output against the master cloud

Definition at line 245 of file OpticalFlowSegmentation.hpp.

◆ resegStartingChain_

Chain volcart::segmentation::OpticalFlowSegmentation::resegStartingChain_
private

Re-segmentation starting chain provided by the caller

Definition at line 251 of file OpticalFlowSegmentation.hpp.

◆ smoothByBrightness_

std::uint8_t volcart::segmentation::OpticalFlowSegmentation::smoothByBrightness_ {180}
private

This parameter sets the threshold for what pixel brightness is considered as being outside the sheet. Pixels considered outside the sheet are smoothed in an attempt to get them tracking the sheet again. Range: 0-255. Smooth curve at pixels above this threshold.

Definition at line 235 of file OpticalFlowSegmentation.hpp.

◆ startIndex_

int volcart::segmentation::OpticalFlowSegmentation::startIndex_ {0}
private

Start z-index

Definition at line 201 of file OpticalFlowSegmentation.hpp.

◆ visualize_

bool volcart::segmentation::OpticalFlowSegmentation::visualize_ {false}
private

Show visualization in GUI flag

Definition at line 261 of file OpticalFlowSegmentation.hpp.


The documentation for this class was generated from the following file: