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 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<PeripathDetector.Detection> detections, ij.ImagePlus imp, String name, Color color)
      Creates a grouped PointRoi from a list of PeripathDetector.Detections. Each detection's pixel coordinates and stack position are computed via PeripathDetector.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)
    • saveRoisToZip

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

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