image2data#

crispy.image_ridge_find.image2data(image, thres=0.5, ordXYZ=True, walkerThres=None, overmask=None, min_size=9)[source]#

Convert an image into a format compatible with the SCMS algorithm.

This function processes the input image to generate data structures required for ridge finding using the SCMS algorithm. It filters the image based on intensity thresholds and optionally removes small structures.

Parameters:
  • image (ndarray) – Input image as a NumPy array.

  • thres (float, optional, default=0.5) – Minimum intensity value for a pixel to be included in the SCMS run. Pixels below this threshold are ignored.

  • ordXYZ (bool, optional, default=True) – If True, reorders coordinates to XYZ format (native Python uses ZYX). Supports n-dimensional equivalents for higher-dimensional data.

  • walkerThres (float, optional) – Minimum intensity value for placing walkers. Defaults to 1.1 * thres if not specified.

  • overmask (ndarray of bool, optional) – Boolean mask specifying additional voxels to include in the SCMS run, supplementing the threshold-based mask.

  • min_size (int, optional, default=9) – Minimum size (in pixels) for connected structures to be retained. Smaller structures are removed for noise suppression.

Returns:

  • X (ndarray) – Pixel coordinates of the input image that meet the intensity threshold, formatted for kernel density estimation.

  • G (ndarray) – Initial walker positions for the SCMS algorithm, derived from the threshold mask or walkerThres.

  • weights (ndarray) – Intensity values of the pixels in X, representing their weights.

  • D (int) – Dimensionality of the input image (e.g., 2D or 3D).

Notes

  • The function automatically handles small structure removal when min_size is set.

  • If no walkerThres is provided, it defaults to slightly above thres (1.1 * thres).

  • The ordXYZ parameter ensures compatibility with SCMS expectations, which use XYZ ordering.

Examples

Prepare image data for ridge finding:

>>> import numpy as np
>>> from crispy import image_ridge_find as irf
>>> image = np.random.random((100, 100))
>>> X, G, weights, D = irf.image2data(image, thres=0.2, min_size=5)

Use a custom mask to include specific voxels:

>>> mask = np.zeros_like(image, dtype=bool)
>>> mask[10:20, 10:20] = True
>>> X, G, weights, D = irf.image2data(image, thres=0.2, overmask=mask)