Package sc.fiji.snt.tracing.auto
Class SomaUtils
java.lang.Object
sc.fiji.snt.tracing.auto.SomaUtils
Utilities for automatic soma detection and ROI generation.
Provides methods to detect the soma (cell body) in fluorescent images using a combined EDT-intensity approach, flood fill the region, extract contours, and convert to ImageJ ROIs.
Three detection modes are available:detectSoma(net.imagej.ImgPlus<?>, double, int)- Detect single soma (brightest/thickest region)detectSomaAt(net.imglib2.RandomAccessibleInterval<? extends net.imglib2.type.numeric.RealType<?>>, long, long, double, double[])- Detect soma at a specific seed pointdetectAllSomas(net.imglib2.RandomAccessibleInterval<? extends net.imglib2.type.numeric.RealType<?>>, double, double[], double)- Detect all somas in the image
- Author:
- Tiago Ferreira
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordContainer for soma detection results. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic doublecomputeMaskArea(net.imglib2.img.Img<net.imglib2.type.logic.BitType> mask, double[] spacing) Computes the area of a binary mask.static double[]computeMaskCentroid(net.imglib2.img.Img<net.imglib2.type.logic.BitType> mask, double[] spacing) Computes the centroid of a binary mask.static doublecomputeOtsuThreshold(net.imglib2.RandomAccessibleInterval<? extends net.imglib2.type.numeric.RealType<?>> source) Computes Otsu's threshold using ImageJ Ops.static List<SomaUtils.SomaResult> detectAllSomas(net.imagej.ImgPlus<?> source) Detects all somas using ImgPlus with default settings.static List<SomaUtils.SomaResult> detectAllSomas(net.imagej.ImgPlus<?> source, double threshold, int zSlice, double minRadius) Detects all somas using ImgPlus with automatic spacing.static List<SomaUtils.SomaResult> detectAllSomas(net.imglib2.RandomAccessibleInterval<? extends net.imglib2.type.numeric.RealType<?>> source, double threshold, double[] spacing) Detects all somas using default minimum radius.static List<SomaUtils.SomaResult> detectAllSomas(net.imglib2.RandomAccessibleInterval<? extends net.imglib2.type.numeric.RealType<?>> source, double threshold, double[] spacing, double minRadius) Detects all somas using EDT local maxima approach.static SomaUtils.SomaResultdetectSoma(net.imagej.ImgPlus<?> source) Full soma detection using ImgPlus with automatic thresholding.static SomaUtils.SomaResultdetectSoma(net.imagej.ImgPlus<?> source, double threshold, int zSlice) Full soma detection using ImgPlus with spacing extracted automatically.static SomaUtils.SomaResultdetectSoma(net.imglib2.RandomAccessibleInterval<? extends net.imglib2.type.numeric.RealType<?>> source, double threshold, double[] spacing) Full soma detection: finds center, floods region, extracts contour.static SomaUtils.SomaResultdetectSomaAt(net.imagej.ImgPlus<?> source, long seedX, long seedY, double threshold, int zSlice) Detects soma at a specific seed point using ImgPlus.static SomaUtils.SomaResultdetectSomaAt(net.imglib2.RandomAccessibleInterval<? extends net.imglib2.type.numeric.RealType<?>> source, long seedX, long seedY, double threshold, double[] spacing) Detects soma at a specific seed point.static PolygonExtracts the boundary contour from a binary mask using Moore boundary tracing.floodFillSoma(net.imglib2.RandomAccessibleInterval<? extends net.imglib2.type.numeric.RealType<?>> source, long seedX, long seedY, double threshold) Creates a binary mask of the soma region using flood fill from seed point.static PathroiToSomaPath(ij.gui.Roi roi, double[] spacing) Creates a single-node soma Path from an ImageJ ROI.static PathroiToSomaPath(ij.gui.Roi roi, Path referencePath) Creates a single-node soma Path from an ImageJ ROI using calibration from a reference Path.
-
Field Details
-
OUTPUT_POINT
Output type: Point ROI at soma center- See Also:
-
OUTPUT_CONTOUR
Output type: Area ROI from flood fill contour- See Also:
-
OUTPUT_CIRCLE
Output type: Circular ROI with estimated radius- See Also:
-
-
Method Details
-
detectSoma
public static SomaUtils.SomaResult detectSoma(net.imagej.ImgPlus<?> source, double threshold, int zSlice) Full soma detection using ImgPlus with spacing extracted automatically.Convenience method that extracts spacing from the ImgPlus calibration.
- Parameters:
source- input image (2D or 3D ImgPlus)threshold- intensity threshold. Use -1 for Otsu, NaN for mean.zSlice- Z-slice to use (0-indexed), or -1 for middle slice- Returns:
- SomaResult containing center, mask, contour, and radius; or null if detection fails
- See Also:
-
detectSoma
Full soma detection using ImgPlus with automatic thresholding.Convenience method using Otsu's threshold and spacing from ImgPlus calibration.
- Parameters:
source- input image (2D or 3D ImgPlus)- Returns:
- SomaResult containing center, mask, contour, and radius; or null if detection fails
- See Also:
-
detectSoma
public static SomaUtils.SomaResult detectSoma(net.imglib2.RandomAccessibleInterval<? extends net.imglib2.type.numeric.RealType<?>> source, double threshold, double[] spacing) Full soma detection: finds center, floods region, extracts contour.- Parameters:
source- input image (2D)threshold- intensity threshold. Use -1 for Otsu, NaN for mean.spacing- voxel spacing [x, y], or null for unit spacing- Returns:
- SomaResult containing center, mask, contour, and radius; or null if detection fails
-
detectSomaAt
public static SomaUtils.SomaResult detectSomaAt(net.imglib2.RandomAccessibleInterval<? extends net.imglib2.type.numeric.RealType<?>> source, long seedX, long seedY, double threshold, double[] spacing) Detects soma at a specific seed point.Useful for interactive detection where user clicks near a soma.
- Parameters:
source- input image (2D)seedX- X coordinate of seed point (voxels)seedY- Y coordinate of seed point (voxels)threshold- intensity threshold. Use -1 for Otsu, NaN for mean.spacing- voxel spacing [x, y], or null for unit spacing- Returns:
- SomaResult, or null if seed is in background or detection fails
-
detectSomaAt
public static SomaUtils.SomaResult detectSomaAt(net.imagej.ImgPlus<?> source, long seedX, long seedY, double threshold, int zSlice) Detects soma at a specific seed point using ImgPlus.- Parameters:
source- input image (2D or 3D ImgPlus)seedX- X coordinate of seed point (voxels)seedY- Y coordinate of seed point (voxels)threshold- intensity threshold. Use -1 for Otsu, NaN for mean.zSlice- Z-slice to use (0-indexed), or -1 for middle slice- Returns:
- SomaResult, or null if seed is in background or detection fails
-
detectAllSomas
public static List<SomaUtils.SomaResult> detectAllSomas(net.imglib2.RandomAccessibleInterval<? extends net.imglib2.type.numeric.RealType<?>> source, double threshold, double[] spacing, double minRadius) Detects all somas using EDT local maxima approach. Finds local maxima in the distance transform - these correspond to centers of thick structures (somas), not thin structures (neurites).- Parameters:
source- input image (2D)threshold- intensity threshold. Use -1 for Otsu, NaN for mean.spacing- voxel spacing [x, y], or null for unit spacingminRadius- minimum soma radius in voxels to include (filters small debris)- Returns:
- list of SomaResult, sorted by radius (largest first); empty list if none found
-
detectAllSomas
public static List<SomaUtils.SomaResult> detectAllSomas(net.imglib2.RandomAccessibleInterval<? extends net.imglib2.type.numeric.RealType<?>> source, double threshold, double[] spacing) Detects all somas using default minimum radius.- Parameters:
source- input image (2D)threshold- intensity threshold. Use -1 for Otsu, NaN for mean.spacing- voxel spacing [x, y], or null for unit spacing- Returns:
- list of SomaResult, sorted by radius (largest first)
-
detectAllSomas
public static List<SomaUtils.SomaResult> detectAllSomas(net.imagej.ImgPlus<?> source, double threshold, int zSlice, double minRadius) Detects all somas using ImgPlus with automatic spacing.- Parameters:
source- input image (2D or 3D ImgPlus)threshold- intensity threshold. Use -1 for Otsu, NaN for mean.zSlice- Z-slice to use (0-indexed), or -1 for middle sliceminRadius- minimum soma radius in voxels- Returns:
- list of SomaResult, sorted by radius (largest first)
-
detectAllSomas
Detects all somas using ImgPlus with default settings.- Parameters:
source- input image (2D or 3D ImgPlus)- Returns:
- list of SomaResult, sorted by radius (largest first)
-
floodFillSoma
public static net.imglib2.img.Img<net.imglib2.type.logic.BitType> floodFillSoma(net.imglib2.RandomAccessibleInterval<? extends net.imglib2.type.numeric.RealType<?>> source, long seedX, long seedY, double threshold) Creates a binary mask of the soma region using flood fill from seed point.- Parameters:
source- the input image (2D)seedX- seed X coordinate (voxels)seedY- seed Y coordinate (voxels)threshold- pixels above this value are considered foreground- Returns:
- binary mask where TRUE = soma region, or null if seed is in background
-
extractContour
Extracts the boundary contour from a binary mask using Moore boundary tracing.- Parameters:
mask- binary mask (TRUE = foreground)- Returns:
- polygon contour, or null if mask is empty
-
computeMaskCentroid
public static double[] computeMaskCentroid(net.imglib2.img.Img<net.imglib2.type.logic.BitType> mask, double[] spacing) Computes the centroid of a binary mask.- Parameters:
mask- binary maskspacing- voxel spacing [x, y] for physical coordinates, or null for voxel coords- Returns:
- centroid as [x, y], or null if mask is empty
-
computeMaskArea
public static double computeMaskArea(net.imglib2.img.Img<net.imglib2.type.logic.BitType> mask, double[] spacing) Computes the area of a binary mask.- Parameters:
mask- binary maskspacing- voxel spacing [x, y], or null for voxel count- Returns:
- area in physical units squared, or voxel count if spacing is null
-
computeOtsuThreshold
public static double computeOtsuThreshold(net.imglib2.RandomAccessibleInterval<? extends net.imglib2.type.numeric.RealType<?>> source) Computes Otsu's threshold using ImageJ Ops.- Parameters:
source- the input image- Returns:
- Otsu threshold value
-
roiToSomaPath
Creates a single-node soma Path from an ImageJ ROI using calibration from a reference Path.- Parameters:
roi- the ROI to convert (must not be null)referencePath- a Path from which to extract spacing and units (may be null for pixel units)- Returns:
- a single-node soma path, or null if ROI is null
- See Also:
-
roiToSomaPath
Creates a single-node soma Path from an ImageJ ROI.Converts any ROI to a soma path centered at the ROI's centroid. For area ROIs (polygon, oval, freehand, etc.), the radius is estimated from the equivalent circle area. For non-area ROIs (point, line), no radius is assigned.
- Parameters:
roi- the ROI to convert (must not be null)spacing- voxel spacing [x, y, z] for physical coordinates, or null for pixel units- Returns:
- a single-node soma path, or null if ROI is null
-