linumpy.geometry.interface#

Tissue interface detection and fitting.

Functions#

find_tissue_depth(vol[, zmin, zmax, agarose_intensity])

Detect the tissue interface depth in given volume.

get_interface_depth_from_mask(vol)

Compute the interface depths from a 3D tissue mask.

find_tissue_interface(vol[, s_xy, s_z, use_log, mask, ...])

Detect the tissue interface.

find_cutting_plane(vol, z0map, agarose_mean, agarose_std)

Find the cutting plane using agarose segmentation.

remove_z0_outliers(z0map)

Remove outlier interface depths from the z0 map using median absolute deviation.

fit_interface(…)

Fit a model on the given interface.

quadratic_interface(pos, a, b, c, d, e, f, g, h)

Evaluate a quadratic surface model for the tissue interface.

get_quadratic_interface(popt[, volshape])

Compute the tissue interface map from quadratic fit parameters.

linear_homogeneous_profile(z, z0, dz, I0, Ib, sigma)

Intensity profile based on a single homogeneous tissue Beer-Lambert model (covered by some amount of water).

estimate_lh_profile_parameters(vol[, s])

Estimates the linear-homogeneous intensity profile parameters.

detect_interface_z(vol[, sigma_xy, sigma_z, use_log])

Detect water/tissue interface along Z using gradient-based method.

Module Contents#

linumpy.geometry.interface.find_tissue_depth(vol, zmin=15, zmax=100, agarose_intensity=5000)[source]#

Detect the tissue interface depth in given volume.

This algorithm first segments the volume into tissue vs background(agarose) using the Li thresholding method and user-defined agarose intensity value. It then computes the XZ mean projection of the tissue mask, and detects the main edge position of the tissue/water interface using morphological operations and relative maximum detection. Other operations are done on the data to reduce the effect of intensity noise and artefacts on the water/tissue interface depth detection.

Parameters:
  • vol (ndarray) – Volume to analyze

  • zmin (int) – Minimum depth of interface in pixel

  • zmax (int) – Maximum depth of interface in pixel

  • agarose_intensity (int) – Agarose mean intensity value used to restrict analysis to tissue voxels

Returns:

Tissue interface depth

Return type:

int

Notes

  • The default depth is 40 px

linumpy.geometry.interface.get_interface_depth_from_mask(vol)[source]#

Compute the interface depths from a 3D tissue mask.

Parameters:

vol ((NxMxK) ndarray) – Tissue mask

Returns:

ndarray – Interface depth (in pixel)

Return type:

(NxM)

linumpy.geometry.interface.find_tissue_interface(vol, s_xy=15, s_z=2, use_log=True, mask=None, order=1, detect_cutting_errors=False)[source]#

Detect the tissue interface.

Parameters:
  • vol (ndarray) – Containing the volume to analyze

  • s_xy (int) – Uniform filter kernel size (xy)

  • s_z (int) – 1st order gaussian kernel size (z)

  • use_log (bool) – If True, apply log transform before filtering.

  • mask (ndarray, optional) – Optional mask restricting the analysis region.

  • order (int) – Gaussian filter order.

  • detect_cutting_errors (bool) – If True, detect and correct cutting artefacts.

Returns:

Tissue interface depth

Return type:

ndarray

linumpy.geometry.interface.find_cutting_plane(vol, z0map, agarose_mean, agarose_std)[source]#

Find the cutting plane using agarose segmentation.

Parameters:
  • vol (ndarray) – Input volume.

  • z0map (ndarray) – Interface depth map.

  • agarose_mean (float) – Mean intensity of agarose.

  • agarose_std (float) – Standard deviation of agarose intensity.

Returns:

  • popt

  • detected_interface (ndarray)

  • z0 (int)

Return type:

tuple[numpy.ndarray, numpy.ndarray, float]

linumpy.geometry.interface.remove_z0_outliers(z0map)[source]#

Remove outlier interface depths from the z0 map using median absolute deviation.

Parameters:

z0map (numpy.ndarray)

Return type:

numpy.ndarray

linumpy.geometry.interface.fit_interface(interface: numpy.ndarray, method: str = ..., return_center: Literal[False] = ...) numpy.ndarray[source]#
linumpy.geometry.interface.fit_interface(interface: numpy.ndarray, method: str = ..., return_center: Literal[True] = ...) tuple[numpy.ndarray, tuple[float, float]]

Fit a model on the given interface.

Parameters:
  • interface (ndarray) – Interface depth map to fit.

  • method (str) – Fitting method: ‘linear’, ‘quad’, ‘gauss’, or ‘sph’.

  • return_center (bool) – If True, also return the center of the fitted surface.

linumpy.geometry.interface.quadratic_interface(pos, a, b, c, d, e, f, g, h)[source]#

Evaluate a quadratic surface model for the tissue interface.

Parameters:
Return type:

numpy.ndarray

linumpy.geometry.interface.get_quadratic_interface(popt, volshape=(512, 512, 120))[source]#

Compute the tissue interface map from quadratic fit parameters.

Parameters:
Return type:

numpy.ndarray

linumpy.geometry.interface.linear_homogeneous_profile(z, z0, dz, I0, Ib, sigma)[source]#

Intensity profile based on a single homogeneous tissue Beer-Lambert model (covered by some amount of water).

This will return the log(I).

Parameters:
  • z (ndarray) – Position where the intensity is evaluated

  • z0 (float) – Water-tissue interface depth

  • dz (float) – Interface Transition width

  • I0 (float) – Top tissue slice intensity (physics notation)

  • Ib (float) – Water intensity (physics notation)

  • sigma (float) – Tissue Attenuation coefficient

Returns:

Log(I) evaluated at each position z.

Return type:

ndarray

linumpy.geometry.interface.estimate_lh_profile_parameters(vol, s=25)[source]#

Estimates the linear-homogeneous intensity profile parameters.

Parameters:
  • vol (ndarray) – Volume for which the LHP parameters are evaluated

  • s (int) – Neighborhood used to average intensities at each depth

Returns:

  • float – z0 : Water-tissue interface depth

  • float – dz : Interface Transition width

  • float – I0 : Top tissue slice intensity

  • float – Ib : water intensity

  • float – sigma : Tissue Attenuation coefficient

Return type:

tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray]

Note

  • This first version loops over all intensity profiles (x, y)

linumpy.geometry.interface.detect_interface_z(vol, sigma_xy=3.0, sigma_z=2.0, use_log=False)[source]#

Detect water/tissue interface along Z using gradient-based method.

Applies Gaussian smoothing then finds the peak of the first-order Z-derivative to locate the tissue surface.

Parameters:
  • vol (np.ndarray) – Volume with shape (X, Y, Z) – already transposed from OME-Zarr (Z, X, Y).

  • sigma_xy (float) – Gaussian smoothing sigma in XY before Z-gradient.

  • sigma_z (float) – Gaussian smoothing sigma for Z-gradient computation.

  • use_log (bool) – Apply log transform before gradient detection.

Returns:

Estimated interface depth in Z voxels.

Return type:

int