Class CrossSectionUtils

java.lang.Object
sc.fiji.snt.tracing.CrossSectionUtils

public final class CrossSectionUtils extends Object
Static utilities for computing cross-sectional planes perpendicular to a path tangent. Extracted from PathFitter for reuse by other path-analysis tools (e.g., varicosity detection, torus mask generation).
Author:
Tiago Ferreira, Cameron Arshadi
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    applyAnnularMask(ij.process.FloatProcessor fp, double innerRadius, double outerRadius)
    Applies an annular mask to a cross-section FloatProcessor.
    static void
    applyAnnularMask1D(float[] profile, double innerRadius, double outerRadius)
    Applies an annular mask to a 1D profile.
    static double[]
    backProject(int gridX, int gridY, int side, double scaleIso, double ox, double oy, double oz, double[] aBasis, double[] bBasis)
    Back-projects a 2D cross-section grid coordinate to 3D world coordinates.
    static int
    computeGridSize(double physicalRadius, double scale, int maxSide)
    Computes the grid size needed to cover a given physical radius at the specified scale, capped to a maximum.
    static double
    computeIsotropicScale(double[] aBasis, double[] bBasis, double xSpacing, double ySpacing, double zSpacing)
    Computes the isotropic scale for a cross-section plane given the tangent plane basis vectors and voxel spacing.
    static double
    computeScaleAlongVector(double vx, double vy, double vz, double xSpacing, double ySpacing, double zSpacing)
    Computes the effective physical scale along an arbitrary direction vector given anisotropic voxel spacing.
    static double[][]
    computeTangentPlaneBasis(double nx, double ny, double nz)
    Computes an orthonormal basis for the plane perpendicular to the given normal (tangent) vector.
    static int[]
    findMaxima1D(float[] profile, double prominence)
    Finds local maxima in a 1D profile using prominence-based filtering.
    static <T extends net.imglib2.type.numeric.RealType<T>>
    void
    paintAnnulus(net.imglib2.RandomAccessibleInterval<T> output, int side, double scaleIso, double ox, double oy, double oz, double[] aBasis, double[] bBasis, double xSpacing, double ySpacing, double zSpacing, double innerRadius, double outerRadius, double fillValue)
    Paints an annular cross-section into a 3D output image.
    static ij.process.FloatProcessor
    sampleCrossSection(int side, double scaleA, double scaleB, double ox, double oy, double oz, double[] aBasis, double[] bBasis, double xSpacing, double ySpacing, double zSpacing, net.imglib2.RealRandomAccess<net.imglib2.type.numeric.real.FloatType> realAccess)
    Samples a square cross-section of an image on the plane perpendicular to a path tangent at a given node position.
    static float[]
    sampleProfile(int nSamples, double scale, double ox, double oy, double[] direction, double xSpacing, double ySpacing, net.imglib2.RealRandomAccess<net.imglib2.type.numeric.real.FloatType> realAccess)
    Samples a 1D intensity profile along a direction vector, centered on a given world position.

    Methods inherited from class java.lang.Object

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

    • computeTangentPlaneBasis

      public static double[][] computeTangentPlaneBasis(double nx, double ny, double nz)
      Computes an orthonormal basis for the plane perpendicular to the given normal (tangent) vector.
      Parameters:
      nx - X component of the normal vector
      ny - Y component of the normal vector
      nz - Z component of the normal vector
      Returns:
      double[2][3]: [0] is the first basis vector, [1] is the second basis vector
    • computeScaleAlongVector

      public static double computeScaleAlongVector(double vx, double vy, double vz, double xSpacing, double ySpacing, double zSpacing)
      Computes the effective physical scale along an arbitrary direction vector given anisotropic voxel spacing.
      Parameters:
      vx - X component of direction vector
      vy - Y component of direction vector
      vz - Z component of direction vector
      xSpacing - voxel width
      ySpacing - voxel height
      zSpacing - voxel depth
      Returns:
      effective scale (physical distance per unit in the given direction)
    • sampleCrossSection

      public static ij.process.FloatProcessor sampleCrossSection(int side, double scaleA, double scaleB, double ox, double oy, double oz, double[] aBasis, double[] bBasis, double xSpacing, double ySpacing, double zSpacing, net.imglib2.RealRandomAccess<net.imglib2.type.numeric.real.FloatType> realAccess)
      Samples a square cross-section of an image on the plane perpendicular to a path tangent at a given node position. The section is centered on the node and oriented according to the precomputed basis vectors.
      Parameters:
      side - grid size in pixels (width = height = side)
      scaleA - physical spacing along first basis vector
      scaleB - physical spacing along second basis vector
      ox - node X position (world/calibrated coordinates)
      oy - node Y position (world/calibrated coordinates)
      oz - node Z position (world/calibrated coordinates)
      aBasis - first basis vector [ax, ay, az]
      bBasis - second basis vector [bx, by, bz]
      xSpacing - voxel width (for converting world→pixel)
      ySpacing - voxel height
      zSpacing - voxel depth
      realAccess - interpolating accessor into the source image
      Returns:
      the sampled cross-section as a FloatProcessor
    • applyAnnularMask

      public static void applyAnnularMask(ij.process.FloatProcessor fp, double innerRadius, double outerRadius)
      Applies an annular mask to a cross-section FloatProcessor. Pixels outside the annulus (closer than innerRadius or farther than outerRadius from center) are set to Float.NaN.
      Parameters:
      fp - the cross-section image to mask (modified in place)
      innerRadius - inner radius in grid pixels (0 for solid disk)
      outerRadius - outer radius in grid pixels
    • backProject

      public static double[] backProject(int gridX, int gridY, int side, double scaleIso, double ox, double oy, double oz, double[] aBasis, double[] bBasis)
      Back-projects a 2D cross-section grid coordinate to 3D world coordinates.
      Parameters:
      gridX - grid X coordinate (pixel in the cross-section)
      gridY - grid Y coordinate (pixel in the cross-section)
      side - cross-section grid size
      scaleIso - isotropic physical scale of the grid
      ox - node X position (world coordinates)
      oy - node Y position (world coordinates)
      oz - node Z position (world coordinates)
      aBasis - first basis vector [ax, ay, az]
      bBasis - second basis vector [bx, by, bz]
      Returns:
      double[3] world coordinates {x, y, z}
    • computeIsotropicScale

      public static double computeIsotropicScale(double[] aBasis, double[] bBasis, double xSpacing, double ySpacing, double zSpacing)
      Computes the isotropic scale for a cross-section plane given the tangent plane basis vectors and voxel spacing.
      Parameters:
      aBasis - first basis vector
      bBasis - second basis vector
      xSpacing - voxel width
      ySpacing - voxel height
      zSpacing - voxel depth
      Returns:
      the isotropic scale (geometric mean of scales along both basis vectors)
    • computeGridSize

      public static int computeGridSize(double physicalRadius, double scale, int maxSide)
      Computes the grid size needed to cover a given physical radius at the specified scale, capped to a maximum.
      Parameters:
      physicalRadius - radius in calibrated units
      scale - physical units per grid pixel
      maxSide - maximum allowed grid size
      Returns:
      the grid size (always odd, so center pixel is well-defined)
    • sampleProfile

      public static float[] sampleProfile(int nSamples, double scale, double ox, double oy, double[] direction, double xSpacing, double ySpacing, net.imglib2.RealRandomAccess<net.imglib2.type.numeric.real.FloatType> realAccess)
      Samples a 1D intensity profile along a direction vector, centered on a given world position. Intended for 2D images where the cross-section perpendicular to a path tangent is a line, not a plane.
      Parameters:
      nSamples - number of samples (should be odd so center is well-defined)
      scale - physical spacing per sample along the direction
      ox - center X position (world/calibrated coordinates)
      oy - center Y position (world/calibrated coordinates)
      direction - direction vector [dx, dy] (unit length)
      xSpacing - voxel width (for converting world→pixel)
      ySpacing - voxel height
      realAccess - interpolating accessor into the source image (2D)
      Returns:
      the sampled profile as a float array
    • applyAnnularMask1D

      public static void applyAnnularMask1D(float[] profile, double innerRadius, double outerRadius)
      Applies an annular mask to a 1D profile. Samples closer than innerRadius or farther than outerRadius from the center are set to Float.NaN.
      Parameters:
      profile - the profile array (modified in place)
      innerRadius - inner radius in sample units (0 for no inner exclusion)
      outerRadius - outer radius in sample units
    • findMaxima1D

      public static int[] findMaxima1D(float[] profile, double prominence)
      Finds local maxima in a 1D profile using prominence-based filtering. A sample is a local maximum if it is strictly greater than both its neighbors (ignoring NaN) and its prominence exceeds the threshold. Prominence is defined as the peak value minus the highest saddle point connecting the peak to any higher peak (or the profile boundary).
      Parameters:
      profile - the 1D intensity profile (may contain NaN for masked regions)
      prominence - minimum prominence threshold
      Returns:
      array of indices into profile where maxima were found
    • paintAnnulus

      public static <T extends net.imglib2.type.numeric.RealType<T>> void paintAnnulus(net.imglib2.RandomAccessibleInterval<T> output, int side, double scaleIso, double ox, double oy, double oz, double[] aBasis, double[] bBasis, double xSpacing, double ySpacing, double zSpacing, double innerRadius, double outerRadius, double fillValue)
      Paints an annular cross-section into a 3D output image. For each pixel in the annulus (between innerRadius and outerRadius in grid space), the corresponding voxel in the output image is set to fillValue. Existing non-zero voxels are preserved (logical OR).
      Type Parameters:
      T - pixel type (must support setReal)
      Parameters:
      output - the 3D output image (modified in place); dimensions correspond to pixel coordinates
      side - cross-section grid size in pixels
      scaleIso - isotropic physical scale of the grid
      ox - node X position (world/calibrated coordinates)
      oy - node Y position (world/calibrated coordinates)
      oz - node Z position (world/calibrated coordinates)
      aBasis - first tangent plane basis vector
      bBasis - second tangent plane basis vector
      xSpacing - voxel width
      ySpacing - voxel height
      zSpacing - voxel depth
      innerRadius - inner radius in grid pixels (0 for solid disk)
      outerRadius - outer radius in grid pixels
      fillValue - the value to write into annulus voxels