Class RoiConverter

java.lang.Object
sc.fiji.snt.analysis.RoiConverter

public class RoiConverter extends Object
Converts SNT Paths into (IJ1) ROIs.
Author:
Tiago Ferreira
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    SNT's XY view (the default export plane)
    static final int
    SNT's XZ view
    static final int
    SNT's ZY view
  • Constructor Summary

    Constructors
    Constructor
    Description
    RoiConverter(Collection<Path> paths, ij.ImagePlus imp)
    Instantiates a new Converter.
    RoiConverter(Path path, ij.ImagePlus imp)
    Instantiates a new Converter.
    Instantiates a new Converter.
    RoiConverter(Tree tree, ij.ImagePlus imp)
    Instantiates a new Converter.
  • Method Summary

    Modifier and Type
    Method
    Description
    static ij.gui.Roi
    combine(List<ij.gui.Roi> rois)
     
    static ij.gui.Roi
    convert(Collection<Path> paths, ij.ImagePlus imp)
     
    void
    convertBranches(ij.gui.Overlay overlay)
     
    void
    Converts all the branch points associated with the parsed paths into PointRois, adding them to the overlay of the image specified in the constructor.
    void
    convertBranchPoints(ij.gui.Overlay overlay)
    Converts all the branch points associated with the parsed paths into PointRois
    void
    convertInnerBranches(ij.gui.Overlay overlay)
     
    void
    Converts paths into 2D polyline ROIs (segment paths), adding them to the overlay of the image specified in the constructor.
    ij.gui.Overlay
    convertPaths(ij.gui.Overlay overlay)
    Converts paths into 2D polyline ROIs.
    ij.gui.Overlay
    convertPaths(ij.gui.Overlay overlay, Collection<Path> paths)
    Converts an ad-hoc collection of paths into 2D polyline ROIs.
    void
    convertPrimaryBranches(ij.gui.Overlay overlay)
     
    void
    Converts the starting nodes of primary paths in the parsed pool into PointRois
    void
    convertRoots(ij.gui.Overlay overlay)
    Converts the starting nodes of primary paths in the parsed pool into PointRois
    void
    convertTerminalBranches(ij.gui.Overlay overlay)
     
    void
    Converts all the tips associated with the parsed paths into PointRois, adding them to the overlay of the image specified in the constructor.
    void
    convertTips(ij.gui.Overlay overlay)
    Converts all the tips associated with the parsed paths into PointRois
    static ij.gui.Roi
    enlarge(ij.gui.Roi roi, int pixels)
     
    static ij.gui.Roi
    get2DBoundingBox(Collection<Path> paths, int exportPlane)
     
    static double[]
    get2dCentroid(ij.gui.Roi roi)
     
    static List<long[]>
    getCentroids(Collection<ij.gui.Roi> rois)
    Extracts centroids from a collection of ROIs as integer pixel coordinates.
    static double
    getFittedRadius(ij.ImagePlus imp, ij.gui.Roi areaRoi)
    Retrieves the radius of a circle with the same area of the specified area ROI.
    static List<ij.gui.Roi>
    getROIs(ij.gui.Overlay overlay, int channel, int zSlice, int tFrame)
    Extracts ROIs associated with a specified CZT position.
    List<ij.gui.PolygonRoi>
    getROIs(Path path)
    Gets ROI representations of the specified path.
    List<ij.gui.Roi>
    getZplaneROIs(int zSlice)
    Extracts all the ROIs converted so far associated with the specified Z-plane.
    static List<ij.gui.Roi>
    getZplaneROIs(ij.gui.Overlay overlay, int zSlice)
    Extracts ROIs associated with a specified Z position.
    static List<ij.gui.Roi>
     
    static boolean
    saveRoisToZip(List<ij.gui.Roi> rois, File file)
     
    void
    setStrokeWidth(int width)
    Sets the line width of converted segment paths.
    void
    setView(int view)
    Sets the exporting view for segment paths (XY by default).
    static ij.gui.PointRoi
    toPointRoi(List<Detection> detections, ij.ImagePlus imp, String name, Color color)
    Creates a grouped PointRoi from a list of Detections.
    void
    useSWCcolors(boolean useSWCcolors)
    Specifies coloring of ROIs by SWC type.

    Methods inherited from class java.lang.Object

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

  • Constructor Details

    • RoiConverter

      public RoiConverter(Tree tree)
      Instantiates a new Converter. Since an image has not been specified, C,Z,T positions may not be properly for converted nodes.
      Parameters:
      tree - the Tree to be converted
    • RoiConverter

      public RoiConverter(Path path, ij.ImagePlus imp)
      Instantiates a new Converter.
      Parameters:
      path - the Path to be converted
      imp - the image associated with the Tree, used to properly assign C,T positions of converted nodes
    • RoiConverter

      public RoiConverter(Collection<Path> paths, ij.ImagePlus imp)
      Instantiates a new Converter.
      Parameters:
      paths - the collection of Paths to be converted
      imp - the image associated with the collection, used to properly assign C,T positions of converted nodes
    • RoiConverter

      public RoiConverter(Tree tree, ij.ImagePlus imp)
      Instantiates a new Converter.
      Parameters:
      tree - the Tree to be converted
      imp - the image associated with the Tree, used to properly assign C,T positions of converted nodes
  • Method Details

    • convertPaths

      public ij.gui.Overlay convertPaths(ij.gui.Overlay overlay)
      Converts paths into 2D polyline ROIs.
      Parameters:
      overlay - the target overlay to hold converted paths
      Returns:
      a reference to the overlay holding paths
    • convertPaths

      public ij.gui.Overlay convertPaths(ij.gui.Overlay overlay, Collection<Path> paths)
      Converts an ad-hoc collection of paths into 2D polyline ROIs.
      Parameters:
      overlay - the target overlay to hold converted paths
      paths - the collection of paths to be converted (e.g., a list of branches produced by StrahlerAnalyzer
      Returns:
      a reference to the overlay holding paths
    • getROIs

      public List<ij.gui.PolygonRoi> getROIs(Path path)
      Gets ROI representations of the specified path.

      Converts the path to a list of PolygonRoi objects using the path's name as the ROI name. The conversion respects the current view setting.

      Parameters:
      path - the path to convert
      Returns:
      a list of PolygonRoi objects representing the path
    • convertTips

      public void convertTips(ij.gui.Overlay overlay)
      Converts all the tips associated with the parsed paths into PointRois
      Parameters:
      overlay - the target overlay to hold converted point
      See Also:
    • convertRoots

      public void convertRoots(ij.gui.Overlay overlay)
      Converts the starting nodes of primary paths in the parsed pool into PointRois
      Parameters:
      overlay - the target overlay to hold converted point
    • convertPaths

      public void convertPaths() throws IllegalArgumentException
      Converts paths into 2D polyline ROIs (segment paths), adding them to the overlay of the image specified in the constructor.
      Throws:
      IllegalArgumentException - if this RoiConverter instance is not aware of any image
      See Also:
    • convertBranches

      public void convertBranches(ij.gui.Overlay overlay)
    • convertInnerBranches

      public void convertInnerBranches(ij.gui.Overlay overlay)
    • convertPrimaryBranches

      public void convertPrimaryBranches(ij.gui.Overlay overlay)
    • convertTerminalBranches

      public void convertTerminalBranches(ij.gui.Overlay overlay)
    • convertTips

      public void convertTips() throws IllegalArgumentException
      Converts all the tips associated with the parsed paths into PointRois, adding them to the overlay of the image specified in the constructor.
      Throws:
      IllegalArgumentException - if this RoiConverter instance is not aware of any image
      See Also:
    • convertBranchPoints

      public void convertBranchPoints() throws IllegalArgumentException
      Converts all the branch points associated with the parsed paths into PointRois, adding them to the overlay of the image specified in the constructor.
      Throws:
      IllegalArgumentException - if this RoiConverter instance is not aware of any image
      See Also:
    • convertRoots

      public void convertRoots() throws IllegalArgumentException
      Converts the starting nodes of primary paths in the parsed pool into PointRois
      Throws:
      IllegalArgumentException - if this RoiConverter instance is not aware of any image
      See Also:
    • getZplaneROIs

      public List<ij.gui.Roi> getZplaneROIs(int zSlice)
      Extracts all the ROIs converted so far associated with the specified Z-plane. It is assumed that ROIs are stored in the overlay of the image specified in the constructor.
      Throws:
      IllegalArgumentException - if this RoiConverter instance is not aware of any image
    • convertBranchPoints

      public void convertBranchPoints(ij.gui.Overlay overlay)
      Converts all the branch points associated with the parsed paths into PointRois
      Parameters:
      overlay - the target overlay to hold converted point
      See Also:
    • setView

      public void setView(int view)
      Sets the exporting view for segment paths (XY by default).
      Parameters:
      view - either XY_PLANE, XZ_PLANE or ZY_PLANE.
    • useSWCcolors

      public void useSWCcolors(boolean useSWCcolors)
      Specifies coloring of ROIs by SWC type.
      Parameters:
      useSWCcolors - if true converted ROIs are colored according to their SWC type integer flag
    • setStrokeWidth

      public void setStrokeWidth(int width)
      Sets the line width of converted segment paths. Set it to -1 to have ROIs plotted using the average diameter of the path
      Parameters:
      width - the new stroke width
      See Also:
    • getZplaneROIs

      public static List<ij.gui.Roi> getZplaneROIs(ij.gui.Overlay overlay, int zSlice)
      Extracts ROIs associated with a specified Z position.
      Parameters:
      overlay - the overlay holding ROIs
      zSlice - the z-plane (1-based index)
      Returns:
      the sub-list of ROIs associated with the specified Z position. Note that ROIs with a ZPosition of 0 are considered to be associated with all Z-slices of a stack
    • getROIs

      public static List<ij.gui.Roi> getROIs(ij.gui.Overlay overlay, int channel, int zSlice, int tFrame)
      Extracts ROIs associated with a specified CZT position. Only ROIS with known hyperstackPosition are considered.
      Parameters:
      overlay - the overlay holding ROIs
      channel - the channel (1-based index)
      zSlice - the z-plane (1-based index)
      tFrame - the t-frame (1-based index)
      Returns:
      the sub-list of ROIs associated with the specified CZT position
      See Also:
      • Roi.hasHyperStackPosition()
    • enlarge

      public static ij.gui.Roi enlarge(ij.gui.Roi roi, int pixels)
    • combine

      public static ij.gui.Roi combine(List<ij.gui.Roi> rois)
    • convert

      public static ij.gui.Roi convert(Collection<Path> paths, ij.ImagePlus imp)
    • toPointRoi

      public static ij.gui.PointRoi toPointRoi(List<Detection> detections, ij.ImagePlus imp, String name, Color color)
      Creates a grouped PointRoi from a list of Detections. Each detection's pixel coordinates and stack position are computed via Detection.xyzct().
      Parameters:
      detections - the detections to convert
      imp - the image used to resolve stack positions (channel, Z, frame)
      name - the ROI name, or null for no name
      color - the stroke color, or null for default
      Returns:
      a PointRoi containing all detection points with per-point Z positions
      Throws:
      IllegalArgumentException - if detections or imp is null
    • get2DBoundingBox

      public static ij.gui.Roi get2DBoundingBox(Collection<Path> paths, int exportPlane)
    • getFittedRadius

      public static double getFittedRadius(ij.ImagePlus imp, ij.gui.Roi areaRoi)
      Retrieves the radius of a circle with the same area of the specified area ROI.
      Parameters:
      imp - The image associated with the ROI
      areaRoi - The input area ROI
      Returns:
      the radius (in calibrated units) of a circle with the same area of areaRoi
    • get2dCentroid

      public static double[] get2dCentroid(ij.gui.Roi roi)
    • getCentroids

      public static List<long[]> getCentroids(Collection<ij.gui.Roi> rois)
      Extracts centroids from a collection of ROIs as integer pixel coordinates. Each centroid is computed via get2dCentroid(Roi) and rounded to the nearest pixel. The Z coordinate is derived from Roi.getZPosition(): ROIs associated with a specific slice produce a 0-indexed Z value (getZPosition() - 1); ROIs not associated with a particular slice (getZPosition() == 0) produce z = -1, indicating that the Z position is unresolved and should be determined by the caller. Null ROIs or ROIs whose centroid cannot be determined are silently skipped.
      Parameters:
      rois - the ROIs to extract centroids from
      Returns:
      list of long[]{x, y, z} pixel coordinates (z is 0-indexed, or -1 if the ROI has no slice association), one per valid ROI (may be smaller than input if some ROIs are null/invalid)
      See Also:
    • saveRoisToZip

      public static boolean saveRoisToZip(List<ij.gui.Roi> rois, File file)
    • loadRoisFromZip

      public static List<ij.gui.Roi> loadRoisFromZip(File zipFile)