Class AbstractGWDTTracer<T extends net.imglib2.type.numeric.RealType<T>>
- Type Parameters:
T- pixel type
- All Implemented Interfaces:
AutoTracer
- Direct Known Subclasses:
DiskBackedGWDTTracer,GWDTTracer,SparseGWDTTracer
Subclasses specify storage backend via createStorageBackend().
- GWDT - Gray-weighted distance transform on grayscale (no binarization)
- Fast Marching - Build initial tree from seed using geodesic distance on GWDT
- Hierarchical Pruning - Long-segment-first with intensity-weighted coverage
- Author:
- Tiago Ferreira
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classRepresents a hierarchical segment as defined by APP2. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final byteFast Marching state: voxel distance has been finalized.protected doubleprotected intprotected final long[]static final byteFast Marching state: voxel has not yet been reached.protected booleanprotected doubleprotected doubleprotected final long[]protected doubleprotected final long[]protected doubleprotected booleanprotected doubleprotected long[]protected booleanprotected intprotected final net.imglib2.RandomAccessibleInterval<T> protected final double[]protected doubleprotected doubleprotected StorageBackendstatic final byteFast Marching state: voxel is in the narrow-band trial set.Fields inherited from class sc.fiji.snt.tracing.auto.AbstractAutoTracer
logger, rootStrategy, somaRoi, somaRoiZPosition, verboseFields inherited from interface sc.fiji.snt.tracing.auto.AutoTracer
ROI_CENTROID, ROI_CENTROID_WEIGHTED, ROI_CONTAINED, ROI_EDGE, ROI_UNSET -
Constructor Summary
ConstructorsConstructorDescriptionAbstractGWDTTracer(net.imglib2.RandomAccessibleInterval<T> source, double[] spacing) Creates a new GWDTTracer. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddNeighborsToHeap(long[] pos, net.imglib2.RandomAccess<T> srcRA, PriorityQueue<long[]> heap, double threshold) Add neighbors to Fast Marching heap.protected doubleComputes average voxel spacing, handling both 2D and 3D images.protected voidComputes intensity range for GI normalization.protected double[]computeIntensityWeightedJointCoverage(SWCPoint node, net.imglib2.RandomAccess<net.imglib2.type.numeric.integer.UnsignedShortType> countRA, net.imglib2.RandomAccess<? extends net.imglib2.type.numeric.RealType<?>> srcRA) Computes INTENSITY-WEIGHTED joint coverage fraction (like APP2).protected static double[]createIsotropicSpacing(int nDims) protected abstract StorageBackendCreate the storage backend for this tracer.protected voiddarkNodeAndSegmentPruning(DirectedWeightedGraph graph, double effectiveThreshold) APP2-style dark node and segment pruning.protected long[]Gets the image dimensions.protected doubleprotected double[]Gets the voxel spacing used by this tracer.protected static double[]getSpacing(ij.ImagePlus imp, int nDims) protected voidhierarchicalPrune(DirectedWeightedGraph graph, double effectiveThreshold) Performs hierarchical pruning using intensity-weighted coverage.protected voidindexToPos(long idx, long[] pos) Convert linear index to position, writing to provided array (avoids allocation).booleanReturns whether gap bridging is enabled.protected booleanisInBounds(long[] pos) Checks if a voxel position is within image bounds.static voiditerateNeighbors(int[] delta, int dim, int nDims, Runnable action) Iterates over all neighbor offsets (26-connectivity in 3D).protected voidnodeToVoxelPos(SWCPoint node, long[] pos) Converts an SWCPoint's physical coordinates to voxel position.protected longposToIndex(long[] pos) static longposToIndex(long[] pos, long[] dims) Converts an N-dimensional position to a flat array index using row-major order.protected voidrecalculateRadiiFromImage(DirectedWeightedGraph graph, double effectiveThreshold) Recalculates radii for all nodes using image-based method (like APP2).protected voidresampleCurve(DirectedWeightedGraph graph, double stepSize) Resamples the curve to have evenly spaced points.protected voidrunFastMarching(double threshold, long seedIndex) Run Fast Marching using storage backend.voidsetAllowGap(boolean allow) Sets whether to allow bridging small intensity gaps.voidsetBackgroundThreshold(double threshold) Sets the background threshold.voidsetConnectivityType(int type) Sets the connectivity type for Fast Marching.voidsetLeafPruneEnabled(boolean enabled) Enables or disables leaf pruning (both leaf and joint leaf).voidsetLeafPruneOverlap(double threshold) Sets the leaf pruning overlap threshold.voidsetMinSegmentLength(double lengthInPhysicalUnits) Sets the minimum segment length in physical units.voidsetMinSegmentLengthVoxels(double lengthInVoxels) Sets the minimum segment length in VOXEL units.voidsetResampleEnabled(boolean enabled) Enables/disables resampling.voidsetResampleStep(double step) Sets the resampling step size in voxels.voidsetSeed(long[] voxelCoords) Sets the seed point (soma location) in voxel coordinates.voidsetSeedPhysical(double[] physicalCoords) Sets the seed point in physical coordinates.voidsetSmoothEnabled(boolean enabled) Enables or disables curve smoothing.voidsetSmoothWindowSize(int windowSize) Sets the smoothing window size.voidsetSphereOverlapThreshold(double threshold) Sets the sphere overlap threshold for detecting redundant nodes during hierarchical pruning.voidsetSrRatio(double ratio) Sets the SR (Signal-to-Redundant) ratio threshold used in hierarchical pruning.protected voidsmoothCurve(DirectedWeightedGraph graph, int windowSize) Smooths the final curve using a moving average filter.trace()Traces the neuron and returns a Tree.Traces the structure and returns a DirectedWeightedGraph.Traces the neuron and returns a list of Trees.Methods inherited from class sc.fiji.snt.tracing.auto.AbstractAutoTracer
collapseSomaNodes, collapseSomaToRoiCentroid, collapseSomaToWeightedCentroid, computeAverageRadius, estimateBackgroundThreshold, findGraphRoot, findRoot, findRoot, findRootPhysical, findRootPhysical, findThickestPoint, findThickestPointPhysical, getRootStrategy, getSomaRoi, isInsideSomaRoi, isVerbose, log, removeDisconnectedComponents, setSomaRoi, setSomaRoi, setVerbose, splitAtSomaBoundary
-
Field Details
-
FAR
public static final byte FARFast Marching state: voxel has not yet been reached.- See Also:
-
TRIAL
public static final byte TRIALFast Marching state: voxel is in the narrow-band trial set.- See Also:
-
ALIVE
public static final byte ALIVEFast Marching state: voxel distance has been finalized.- See Also:
-
source
protected final net.imglib2.RandomAccessibleInterval<T extends net.imglib2.type.numeric.RealType<T>> source -
spacing
protected final double[] spacing -
dims
protected final long[] dims -
minBounds
protected final long[] minBounds -
maxBounds
protected final long[] maxBounds -
backgroundThreshold
protected double backgroundThreshold -
lengthThreshVoxels
protected double lengthThreshVoxels -
srRatio
protected double srRatio -
sphereOverlapThreshold
protected double sphereOverlapThreshold -
leafPruneOverlap
protected double leafPruneOverlap -
leafPruneEnabled
protected boolean leafPruneEnabled -
smoothEnabled
protected boolean smoothEnabled -
smoothWindowSize
protected int smoothWindowSize -
resampleEnabled
protected boolean resampleEnabled -
resampleStep
protected double resampleStep -
cnnType
protected int cnnType -
maxIntensity
protected double maxIntensity -
minIntensity
protected double minIntensity -
seedVoxel
protected long[] seedVoxel -
storage
-
-
Constructor Details
-
AbstractGWDTTracer
Creates a new GWDTTracer.- Parameters:
source- the grayscale image to tracespacing- voxel dimensions [x, y, z] in physical units
-
-
Method Details
-
createStorageBackend
Create the storage backend for this tracer. Subclasses override to specify array, sparse, or disk-backed storage. -
getSpacing
protected double[] getSpacing()Description copied from class:AbstractAutoTracerGets the voxel spacing used by this tracer.- Specified by:
getSpacingin classAbstractAutoTracer- Returns:
- array of [x, y, z] spacing values
-
getDimensions
protected long[] getDimensions()Description copied from class:AbstractAutoTracerGets the image dimensions.- Specified by:
getDimensionsin classAbstractAutoTracer- Returns:
- array of dimension sizes
-
createIsotropicSpacing
protected static double[] createIsotropicSpacing(int nDims) -
getSpacing
-
setBackgroundThreshold
public void setBackgroundThreshold(double threshold) Sets the background threshold. Pixels at or below this value are considered background. If negative (default), threshold is auto-computed as the image mean. -
setSrRatio
public void setSrRatio(double ratio) Sets the SR (Signal-to-Redundant) ratio threshold used in hierarchical pruning. Default: 3/9 = 0.333 Segments with signal/redundant >= this ratio are kept. -
setMinSegmentLengthVoxels
public void setMinSegmentLengthVoxels(double lengthInVoxels) Sets the minimum segment length in VOXEL units. Default: 2.0 Segments shorter than this are always pruned. -
setMinSegmentLength
public void setMinSegmentLength(double lengthInPhysicalUnits) Sets the minimum segment length in physical units. Internally converted to voxels using average spacing. -
setSphereOverlapThreshold
public void setSphereOverlapThreshold(double threshold) Sets the sphere overlap threshold for detecting redundant nodes during hierarchical pruning. When a node's sphere has more than this fraction covered by claimed nodes, it's considered redundant. Default: 0.4. Lower = more aggressive pruning. -
setLeafPruneOverlap
public void setLeafPruneOverlap(double threshold) Sets the leaf pruning overlap threshold. Leaves with more than this fraction overlapping parent are pruned. Default: 0.9 -
setLeafPruneEnabled
public void setLeafPruneEnabled(boolean enabled) Enables or disables leaf pruning (both leaf and joint leaf). Default: true -
setSmoothEnabled
public void setSmoothEnabled(boolean enabled) Enables or disables curve smoothing. Default: true -
setSmoothWindowSize
public void setSmoothWindowSize(int windowSize) Sets the smoothing window size. Default: 5 -
setResampleEnabled
public void setResampleEnabled(boolean enabled) Enables/disables resampling. Default: true -
setResampleStep
public void setResampleStep(double step) Sets the resampling step size in voxels. Default: 2.0 Points closer than this distance will be merged. -
setConnectivityType
public void setConnectivityType(int type) Sets the connectivity type for Fast Marching.3D images:
- 1 = 6-connectivity (face neighbors)
- 2 = 18-connectivity (face + edge neighbors) - default
- 3 = 26-connectivity (face + edge + corner neighbors)
- 1 = 4-connectivity (edge neighbors)
- 2, 3 = 8-connectivity (edge + corner neighbors)
- Parameters:
type- connectivity type (1, 2, or 3)
-
setAllowGap
public void setAllowGap(boolean allow) Sets whether to allow bridging small intensity gaps.When enabled, fast marching can cross a single dark voxel to connect broken neurites. The crossing is only allowed if the current voxel is above threshold (i.e., we can step from bright → dark → bright, but not dark → dark).
This is useful for images with fragmented signals or small imaging artifacts, but may falsely connect separate structures.
- Parameters:
allow- true to allow crossing single dark voxels (default: false)
-
isAllowGap
public boolean isAllowGap()Returns whether gap bridging is enabled.- Returns:
- true if single dark voxels can be crossed during tracing
-
setSeed
public void setSeed(long[] voxelCoords) Sets the seed point (soma location) in voxel coordinates. For 2D images, only x and y are used (z is ignored if provided). -
setSeedPhysical
public void setSeedPhysical(double[] physicalCoords) Sets the seed point in physical coordinates. For 2D images, only x and y are used (z is ignored if provided). -
traceToGraph
Description copied from class:AbstractAutoTracerTraces the structure and returns a DirectedWeightedGraph.- Specified by:
traceToGraphin classAbstractAutoTracer- Returns:
- the traced graph
-
runFastMarching
protected void runFastMarching(double threshold, long seedIndex) Run Fast Marching using storage backend. -
addNeighborsToHeap
protected void addNeighborsToHeap(long[] pos, net.imglib2.RandomAccess<T> srcRA, PriorityQueue<long[]> heap, double threshold) Add neighbors to Fast Marching heap. Uses cached arrays to reduce allocations in hot path. -
smoothCurve
Smooths the final curve using a moving average filter.- Parameters:
graph- the graph to smoothwindowSize- the smoothing window (default 5: 2 neighbors on each side)
-
recalculateRadiiFromImage
Recalculates radii for all nodes using image-based method (like APP2). This is critical for accurate coverage detection during pruning. -
darkNodeAndSegmentPruning
APP2-style dark node and segment pruning.Phase 1: Dark Node Pruning (iterative) - For each leaf, if intensity <= background threshold, remove the leaf - Repeat until no more dark leaves found
Phase 2: Dark Segment Pruning - For each terminal branch (path from leaf to branch point): - Delete if average intensity <= background threshold, OR - Delete if >= 20% of nodes are dark (intensity <= threshold)
-
hierarchicalPrune
Performs hierarchical pruning using intensity-weighted coverage.Algorithm: 1. Decompose tree into segments (paths between branch points) 2. Calculate segment length as SUM OF NORMALIZED INTENSITIES (not Euclidean!) 3. Sort segments by length (longest first) 4. For each segment, compute intensity-weighted coverage ratio using PIXEL MASK 5. If coverage > threshold, prune segment and children
-
computeIntensityWeightedJointCoverage
protected double[] computeIntensityWeightedJointCoverage(SWCPoint node, net.imglib2.RandomAccess<net.imglib2.type.numeric.integer.UnsignedShortType> countRA, net.imglib2.RandomAccess<? extends net.imglib2.type.numeric.RealType<?>> srcRA) Computes INTENSITY-WEIGHTED joint coverage fraction (like APP2). Returns [coveredSig, totalSig] where coverage is weighted by image intensity. -
computeIntensityRange
protected void computeIntensityRange()Computes intensity range for GI normalization. APP2 uses actual image min/max, not threshold-based. -
resampleCurve
Resamples the curve to have evenly spaced points. Keeps branch points and endpoints, removes intermediate points that are too close. -
getEffectiveThreshold
protected double getEffectiveThreshold() -
posToIndex
protected long posToIndex(long[] pos) -
posToIndex
public static long posToIndex(long[] pos, long[] dims) Converts an N-dimensional position to a flat array index using row-major order. -
indexToPos
protected void indexToPos(long idx, long[] pos) Convert linear index to position, writing to provided array (avoids allocation). -
nodeToVoxelPos
Converts an SWCPoint's physical coordinates to voxel position. Handles both 2D and 3D images.- Parameters:
node- The SWCPoint with physical coordinatespos- Output array (must be dims.length size)
-
isInBounds
protected boolean isInBounds(long[] pos) Checks if a voxel position is within image bounds. Uses ImgUtils.outOfBounds with cached interval bounds. -
computeAverageSpacing
protected double computeAverageSpacing()Computes average voxel spacing, handling both 2D and 3D images. -
iterateNeighbors
Iterates over all neighbor offsets (26-connectivity in 3D). -
trace
Traces the neuron and returns a Tree.- Returns:
- the traced neuron morphology, or null if tracing fails
-
traceTrees
Traces the neuron and returns a list of Trees.With
AutoTracer.ROI_EDGEstrategy, returns separate trees for each neurite exiting the soma ROI. With other strategies, returns a single tree.- Returns:
- list of traced trees, or empty list if tracing fails
-