Package sc.fiji.snt

Class PathFitter

java.lang.Object
sc.fiji.snt.PathFitter
All Implemented Interfaces:
Callable<Path>

public class PathFitter extends Object implements Callable<Path>
Class for fitting circular cross-sections around existing nodes of a Path in order to compute radii (node thickness) and midpoint refinement of existing coordinates. Thread Safety: When fitting multiple paths in parallel: 1. Call call() in parallel (thread-safe) 2. Call applyFit() sequentially (modifies path hierarchy)

Example: List<PathFitter> fitters = paths.stream() .map(p -> new PathFitter(img, p)) .collect(Collectors.toList()); <p> // Parallel fitting fitters.parallelStream().forEach(PathFitter::call); <p> // Sequential application fitters.forEach(PathFitter::applyFit);

Author:
Tiago Ferreira, Mark Longair, Cameron Arshadi
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static double
    The default value for the smallest angle (in radians) constraining the fit.
    static final int
    Flag specifying that radii at invalid fit locations should fall back to the minimum voxel separation (voxel size)
    static final int
    Flag specifying that radii at invalid fit locations should fall back to the mode of all possible fits
    static final int
    Flag specifying that radii at invalid fit locations should fall back to Double.NaN
    static final int
    Flag specifying that the computed path should only inherit midpoint refinement of node coordinates
    static final int
    Flag specifying that the computed path should only inherit fitted radii attributes
    static final int
    Flag specifying that the computed path should inherit both midpoint refinement of node coordinates and radii
  • Constructor Summary

    Constructors
    Constructor
    Description
    PathFitter(ij.ImagePlus imp, Path path)
    Instantiates a new PathFitter.
    PathFitter(net.imagej.ImgPlus<? extends net.imglib2.type.numeric.RealType<?>> img, Path path)
    Instantiates a new PathFitter.
    PathFitter(net.imglib2.RandomAccessibleInterval<? extends net.imglib2.type.numeric.RealType<?>> img, Path path, double xSpacing, double ySpacing, double zSpacing, String unit)
    Instantiates a new PathFitter directly from pixel data.
    PathFitter(SNT plugin, Path path)
    Instantiates a new PathFitter.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Applies the fitted result to the path.
    void
     
    Takes the signal from the image specified in the constructor to fit cross-section circles around the nodes of input path.
     
    boolean
    Checks whether the fit succeeded.
    void
     
    void
    setCrossSectionRadius(double crossSectionRadius)
    Sets the radius of cross-sectional planes sampled around each node.
    void
    setImage(net.imglib2.RandomAccessibleInterval<? extends net.imglib2.type.numeric.RealType<?>> img)
    Sets the target image
    void
    setNodeRadiusFallback(int fallback)
    Sets the fallback strategy for node radii at locations where fitting failed.
    void
    setProgressCallback(int fitterIndex, sc.fiji.snt.MultiTaskProgress progress)
     
    void
    setReplaceNodes(boolean replaceNodes)
    Sets whether fitting should occur "in place".
    void
    setScope(int scope)
    Sets the fitting scope.
    void
    setShowAnnotatedView(boolean showAnnotatedView)
    Sets whether an interactive image of the result should be displayed.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DEFAULT_MIN_ANGLE

      public static double DEFAULT_MIN_ANGLE
      The default value for the smallest angle (in radians) constraining the fit.
    • RADII

      public static final int RADII
      Flag specifying that the computed path should only inherit fitted radii attributes
      See Also:
    • MIDPOINTS

      public static final int MIDPOINTS
      Flag specifying that the computed path should only inherit midpoint refinement of node coordinates
      See Also:
    • RADII_AND_MIDPOINTS

      public static final int RADII_AND_MIDPOINTS
      Flag specifying that the computed path should inherit both midpoint refinement of node coordinates and radii
      See Also:
    • FALLBACK_NAN

      public static final int FALLBACK_NAN
      Flag specifying that radii at invalid fit locations should fall back to Double.NaN
      See Also:
    • FALLBACK_MIN_SEP

      public static final int FALLBACK_MIN_SEP
      Flag specifying that radii at invalid fit locations should fall back to the minimum voxel separation (voxel size)
      See Also:
    • FALLBACK_MODE

      public static final int FALLBACK_MODE
      Flag specifying that radii at invalid fit locations should fall back to the mode of all possible fits
      See Also:
  • Constructor Details

    • PathFitter

      public PathFitter(ij.ImagePlus imp, Path path)
      Instantiates a new PathFitter.
      Parameters:
      imp - the Image containing the signal to which the fit will be performed
      path - the Path to be fitted. Note that path spacing will change to that of image's voxel size.
    • PathFitter

      public PathFitter(net.imagej.ImgPlus<? extends net.imglib2.type.numeric.RealType<?>> img, Path path)
      Instantiates a new PathFitter.
      Parameters:
      img - the Image containing the signal to which the fit will be performed
      path - the Path to be fitted. Note that path spacing will change to that of image's voxel size.
    • PathFitter

      public PathFitter(net.imglib2.RandomAccessibleInterval<? extends net.imglib2.type.numeric.RealType<?>> img, Path path, double xSpacing, double ySpacing, double zSpacing, String unit)
      Instantiates a new PathFitter directly from pixel data. If img has more than two dimensions, the third dimension is treated as depth.

      Specified pixel dimensions will be applied to Path's spacing values.

      Parameters:
      img - the Image containing the signal to which the fit will be performed
      path - the Path to be fitted
      xSpacing - pixel width in physical distance
      ySpacing - pixel height in physical distance
      zSpacing - pixel depth in physical distance
      unit - spatial calibration unit
    • PathFitter

      public PathFitter(SNT plugin, Path path)
      Instantiates a new PathFitter.
      Parameters:
      plugin - the SNT instance specifying input image. The computation will be performed on the image currently loaded by the plugin, adopting the plugin's spatial calibration
      path - the Path to be fitted
  • Method Details

    • setShowAnnotatedView

      public void setShowAnnotatedView(boolean showAnnotatedView)
      Sets whether an interactive image of the result should be displayed.
      Parameters:
      showAnnotatedView - If true, an interactive stack (cross-section view) of the fit is displayed. Note that this is probably only useful if SNT's UI is visible and functional.
    • setProgressCallback

      public void setProgressCallback(int fitterIndex, sc.fiji.snt.MultiTaskProgress progress)
    • readPreferences

      public void readPreferences()
    • applySettings

      public void applySettings(PathFitter pf)
    • call

      public Path call() throws IllegalArgumentException
      Takes the signal from the image specified in the constructor to fit cross-section circles around the nodes of input path. Computation of fit is confined to the neighborhood specified by setCrossSectionRadius(double).
      Specified by:
      call in interface Callable<Path>
      Returns:
      the reference to the computed result. Note that this Path is *not* automatically set as the fitted version of input Path. That only happens when applyFit() is called.
      Throws:
      IllegalArgumentException
      See Also:
    • applyFit

      public void applyFit()
      Applies the fitted result to the path. For multithreaded processing: Must be called sequentially after all parallel fitting is complete.
    • getPath

      public Path getPath()
      Returns:
      the path being fitted
    • getSucceeded

      public boolean getSucceeded()
      Checks whether the fit succeeded.
      Returns:
      true if fit was successful, false otherwise
    • setCrossSectionRadius

      public void setCrossSectionRadius(double crossSectionRadius)
      Sets the radius of cross-sectional planes sampled around each node.

      At each node, PathFitter samples a square cross-section perpendicular to the path tangent. This radius controls the physical extent of that sampling.

      Parameters:
      crossSectionRadius - the physical search radius (in physical units)
    • setScope

      public void setScope(int scope)
      Sets the fitting scope.
      Parameters:
      scope - Either RADII, MIDPOINTS, or RADII_AND_MIDPOINTS
    • setNodeRadiusFallback

      public void setNodeRadiusFallback(int fallback)
      Sets the fallback strategy for node radii at locations where fitting failed.

      When cross-section fitting fails at a node (e.g., low SNR, ambiguous geometry), this strategy determines what radius value to assign to that node.

      Parameters:
      fallback - the fallback strategy: FALLBACK_MODE, FALLBACK_MIN_SEP, or FALLBACK_NAN
    • setReplaceNodes

      public void setReplaceNodes(boolean replaceNodes)
      Sets whether fitting should occur "in place".
      Parameters:
      replaceNodes - If true, the nodes of the input Path will be replaced by those of the fitted result. If false, the fitted result is kept as a separated Path linked to the input as per Path.getFitted(). Note that in the latter case, some topological operations (e.g., forking) performed on the fitted result may not percolate to the non-fitted Path.
    • setImage

      public void setImage(net.imglib2.RandomAccessibleInterval<? extends net.imglib2.type.numeric.RealType<?>> img)
      Sets the target image
      Parameters:
      img - the Image containing the signal to which the fit will be performed