Class NodeCollector<T extends net.imglib2.type.numeric.RealType<T> & net.imglib2.type.NativeType<T>>

java.lang.Object
sc.fiji.snt.analysis.NodeCollector<T>
Type Parameters:
T - the pixel type of the source image

public class NodeCollector<T extends net.imglib2.type.numeric.RealType<T> & net.imglib2.type.NativeType<T>> extends Object
Collects fixed-size image neighborhoods ("crops") centered on a collection of points (typically Tree tips, branch points, roots, bookmarks, or seeds) and exposes them as RAIs, an ImagePlus stack, or a montage.

The class operates on an ImgPlus so it works with lazy, tile/cell-backed sources (OME-Zarr, N5, HDF5) for large datasets: with the default lazy mode, only the cells overlapping each crop are touched. Materialization to an ImagePlus happens only on demand (e.g., when getStack() or getMontage() is called), so even thousands of small (e.g. 20x20) crops can fit in-RAM.

Out-of-bounds windows (e.g. tips near the image border) are padded with zeros so that every crop in the output has identical dimensions and the resulting montage forms a uniform grid.

Constructors and factories:

Author:
Tiago Ferreira
  • Constructor Details

    • NodeCollector

      public NodeCollector(net.imagej.ImgPlus<T> img, Collection<? extends SNTPoint> points)
      Instantiates a NodeCollector from an arbitrary collection of points.
      Parameters:
      img - the source image. Lazy/cell-backed ImgPluses (OME-Zarr, N5, HDF5) are supported transparently
      points - the points around which crops will be extracted. Points are interpreted in calibrated units, matching the image axis metadata. If a point's onPath is set, the path's own calibration is used for pixel conversion instead; otherwise pixel coordinates are derived from the image axes
  • Method Details

    • fromTips

      public static <T extends net.imglib2.type.numeric.RealType<T> & net.imglib2.type.NativeType<T>> NodeCollector<T> fromTips(net.imagej.ImgPlus<T> img, Tree tree)
      Convenience factory using the tips of tree.
    • fromBranchPoints

      public static <T extends net.imglib2.type.numeric.RealType<T> & net.imglib2.type.NativeType<T>> NodeCollector<T> fromBranchPoints(net.imagej.ImgPlus<T> img, Tree tree)
      Convenience factory using the branch points of tree.
    • fromRoots

      public static <T extends net.imglib2.type.numeric.RealType<T> & net.imglib2.type.NativeType<T>> NodeCollector<T> fromRoots(net.imagej.ImgPlus<T> img, Collection<Tree> trees)
      Convenience factory using the root of every supplied tree.
    • fromNodes

      public static <T extends net.imglib2.type.numeric.RealType<T> & net.imglib2.type.NativeType<T>> NodeCollector<T> fromNodes(net.imagej.ImgPlus<T> img, Tree tree, int everyNth)
      Convenience factory sampling every everyNth node across all paths in tree.
      Parameters:
      everyNth - stride (1 = every node)
    • setWindow

      public NodeCollector<T> setWindow(int wxy, int wz)
      Sets the size of the crop window in pixels.
      Parameters:
      wxy - XY edge length (in pixels). Must be >= 1
      wz - Z slab thickness (in pixels). 1 -> 2D crop; values > 1 produce a 3D slab that can be optionally projected via setProjection(Projection)
    • setWindow

      public NodeCollector<T> setWindow(int wx, int wy, int wz)
      Sets the per-axis crop window (X, Y, Z) in pixels.
    • setChannel

      public NodeCollector<T> setChannel(int channel)
      Sets the channel to crop from (0-indexed). By default, the channel of the point's owning Path is used, falling back to 0 for points with no associated Path.
      Parameters:
      channel - 0-indexed channel, or a negative value to restore the "infer from path" default
    • setFrame

      public NodeCollector<T> setFrame(int frame)
      Sets the time frame to crop from (0-indexed). By default, the frame of the point's owning Path is used, falling back to 0 for points with no associated Path.
    • setMaterialize

      public NodeCollector<T> setMaterialize(boolean materialize)
      If true, crops are materialized to contiguous arrays. If false (default), each crop is a lazy Views.interval(net.imglib2.RandomAccessible<T>, long[], long[]) view into the source, suitable for very large lazy-loaded sources. Materialization is forced when an ImagePlus is requested via getStack() or getMontage().
    • setPointsInPixelSpace

      public NodeCollector<T> setPointsInPixelSpace(boolean pointsInPixelSpace)
      If true, the x/y/z of input points are treated as pixel coordinates (no calibration conversion is performed).

      If false (default), points are assumed to be in calibrated units; SNT points carrying an onPath reference are unscaled via the path's calibration, otherwise the image's axis metadata is used.

    • setProjection

      public NodeCollector<T> setProjection(NodeCollector.Projection projection)
      Sets the z-projection applied to each crop. NodeCollector.Projection.NONE (default) returns the full slab; NodeCollector.Projection.MIP_Z reduces the z-slab of each crop to a single 2D slice via max-intensity projection, which is usually what is wanted for a printable montage.
    • setLabelProvider

      public NodeCollector<T> setLabelProvider(Function<SNTPoint,String> labelProvider)
      Provides per-crop slice labels (used by getStack() and getMontage(int, int, double, int, boolean) when labels are enabled). If unset, labels default to "tip-i pathName".
    • getCrop

      public net.imagej.ImgPlus<T> getCrop(SNTPoint point)
      Returns the crop centered on a single point, respecting the current setMaterialize(boolean), setProjection(Projection), setChannel(int), and setWindow(int, int) settings.

      Prefer this over getCrops() when processing large datasets one point at a time (e.g. to keep peak memory bounded to a single crop)

    • getCrops

      public List<net.imagej.ImgPlus<T>> getCrops()
      Returns the per-point crops as a list of ImgPluses.

      If materialize is false (default), the returned ImgPluses are zero-padded lazy views (out-of-bounds samples yield the zero value of T). If true, each ImgPlus is backed by a contiguous Img.

    • getStack

      public ij.ImagePlus getStack()
      Materializes the crops into a multi-slice ImagePlus (one slice per point, in iteration order).
    • getMontage

      public ij.ImagePlus getMontage()
      Convenience for getMontage(int, int, double, int, boolean) with an automatic grid (cols = ceil(sqrt(n))), scale 1, no border, without labels.
    • getMontage

      public ij.ImagePlus getMontage(int cols, int rows, double scale, int border, boolean labels)
      Builds a montage of the crops via IJ1's MontageMaker.
      Parameters:
      cols - number of columns
      rows - number of rows
      scale - resizing scale of each panel
      border - border thickness in pixels
      labels - whether to render slice labels on each panel
      Returns:
      the montage image