smlmlp.locs_individual_barycenter module
- smlmlp.locs_individual_barycenter(crops, X0, Y0, /, ch=None, *, remove_bkgd=True, channels_pixels_nm=1.0, cuda=False, parallel=False)[source]
Compute individual barycenter localizations from image crops.
For each crop stack, the function computes the intensity barycenter per event, adds the crop origin offsets, and converts coordinates to nanometers using the provided pixel sizes.
- Parameters:
crops (sequence of array-like) – Sequence of crop stacks, one per channel, shaped
(N, Y, X).X0 (array-like) – Detection-aligned 1D vector of x-origin pixel indices.
Y0 (array-like) – Detection-aligned 1D vector of y-origin pixel indices.
ch (array-like or None, optional) – One-based channel index for each detection. Required when
cropshas several channels.channels_pixels_nm (float or sequence, optional) – Pixel size specification. It can be a scalar, a
(py, px)tuple, or a per-channel sequence.cuda (bool, optional) – Whether to execute the computation on GPU.
parallel (bool, optional) – Whether to enable CPU parallelization.
- Returns:
A tuple
(mux, muy, info)where:muxis the detection-aligned x localization array in nanometers,muyis the detection-aligned y localization array in nanometers,infois a dictionary containing reusable intermediate results.
The dictionary contains the following keys:
'channels_pixels_nm'Normalized per-channel pixel sizes used for coordinate conversion.
- Return type:
tuple
Notes
chis converted into per-channel positions and used to splitX0andY0so each origin vector matches the corresponding crop stack.Each crop barycenter is computed in local pixel coordinates; non-positive intensity sums are marked invalid with NaN coordinates.
Local barycenters are shifted by the crop origins, converted to nanometers with the channel pixel size, and remapped to detection order.
Examples
>>> import numpy as np >>> crops = [np.random.rand(3, 5, 5).astype(np.float32)] >>> x0 = np.array([10, 20, 30], dtype=np.float32) >>> y0 = np.array([5, 15, 25], dtype=np.float32) >>> mux, muy, info = locs_individual_barycenter(crops, x0, y0) >>> mux.shape == muy.shape True
>>> pix = [(100.0, 120.0)] >>> mux, muy, info = locs_individual_barycenter(crops, x0, y0, channels_pixels_nm=pix) >>> mux.ndim 1