smlmlp.crop_individual_extract module
- smlmlp.crop_individual_extract(channels, /, fr, x_fit, y_fit, ch=None, *, f0=0, channels_crops_pix=11, channels_pixels_nm=100.0, cuda=False, parallel=False)[source]
Extract individual image crops centered on given coordinates.
This function extracts per-event crops from multi-frame image channels using provided frame indices and spatial coordinates. Crops are grouped per channel and computed either on CPU or GPU.
- Parameters:
channels (sequence of ndarray) – Sequence of image stacks, one per channel.
fr (array-like) – Frame indices (starting at 1).
x_fit (array-like) – Channel-local detection coordinates in nanometers.
y_fit (array-like) – Channel-local detection coordinates in nanometers.
ch (array-like or None, optional) – One-based channel indices for each event. If None, assumes one channel.
channels_crops_pix (int or sequence, optional) – Crop size in pixels. Can be scalar, (h, w), or per-channel.
channels_pixels_nm (float or sequence, optional) – Pixel size in nanometers. Can be scalar, (y, x), or per-channel values.
cuda (bool, optional) – Whether to use GPU acceleration.
parallel (bool, optional) – Whether to enable CPU parallelization.
- Returns:
A tuple
(crops, X0, Y0, info)where:cropsis a list of arrays containing extracted crops per channel,X0is a detection-aligned 1D vector of x-origin pixel coordinates,Y0is a detection-aligned 1D vector of y-origin pixel coordinates,infois a dictionary containing reusable intermediate results.
The dictionary contains the following keys:
'channels_crops_pix'Normalized per-channel crop sizes.
'channels_pixels_nm'Normalized per-channel pixel sizes.
'argsort'Identity indices kept for compatibility with blocks reading this field.
'ch'One-based detection-aligned channel indices used to order
X0andY0.
- Return type:
tuple
Notes
Missing channel labels are replaced by channel one when a single channel is processed, and rejected otherwise.
Crop sizes and pixel sizes are normalized to one value per channel.
The function loops over every channel, extracts the detections where
chmatches that channel, and preserves their relative detection order.Per-channel crop stacks are appended to
cropswhile the corresponding crop origins are written back into the global 1DX0andY0vectors.Crop pixels outside the image bounds are filled with zero.
Examples
>>> import numpy as np >>> channel = np.random.rand(10, 32, 32).astype(np.float32) >>> fr = np.array([1, 2, 3]) >>> x = np.array([100., 150., 200.]) >>> y = np.array([120., 180., 220.]) >>> crops, X0, Y0, info = crop_individual_extract([channel], fr, x, y) >>> len(crops) 1 >>> len(crops[0]) 3 >>> X0.shape (3,)