Package sc.fiji.snt.tracing
Class CrossSectionUtils
java.lang.Object
sc.fiji.snt.tracing.CrossSectionUtils
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 TypeMethodDescriptionstatic voidapplyAnnularMask(ij.process.FloatProcessor fp, double innerRadius, double outerRadius) Applies an annular mask to a cross-sectionFloatProcessor.static voidapplyAnnularMask1D(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 intcomputeGridSize(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 doublecomputeIsotropicScale(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 doublecomputeScaleAlongVector(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>>
voidpaintAnnulus(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.FloatProcessorsampleCrossSection(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.
-
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 vectorny- Y component of the normal vectornz- 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 vectorvy- Y component of direction vectorvz- Z component of direction vectorxSpacing- voxel widthySpacing- voxel heightzSpacing- 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 vectorscaleB- physical spacing along second basis vectorox- 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 heightzSpacing- voxel depthrealAccess- 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-sectionFloatProcessor. Pixels outside the annulus (closer thaninnerRadiusor farther thanouterRadiusfrom center) are set toFloat.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 sizescaleIso- isotropic physical scale of the gridox- 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 vectorbBasis- second basis vectorxSpacing- voxel widthySpacing- voxel heightzSpacing- 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 unitsscale- physical units per grid pixelmaxSide- 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 directionox- 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 heightrealAccess- 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 thaninnerRadiusor farther thanouterRadiusfrom the center are set toFloat.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
profilewhere 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 (betweeninnerRadiusandouterRadiusin grid space), the corresponding voxel in the output image is set tofillValue. 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 coordinatesside- cross-section grid size in pixelsscaleIso- isotropic physical scale of the gridox- 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 vectorbBasis- second tangent plane basis vectorxSpacing- voxel widthySpacing- voxel heightzSpacing- voxel depthinnerRadius- inner radius in grid pixels (0 for solid disk)outerRadius- outer radius in grid pixelsfillValue- the value to write into annulus voxels
-