smlmlp.crop_remove_bkgd module
- smlmlp.crop_remove_bkgd(crops, /, *, cuda=False, parallel=False)[source]
Remove a per-crop background estimated from the border median.
This function estimates the background of each crop from the median value of its border pixels, excluding duplicated corner contributions. The estimated border median is then subtracted from the full crop.
- Parameters:
crops (sequence of ndarray) – Sequence of crop stacks. Each element is expected to have shape
(n_crops, height, width).cuda (bool, optional) – Whether to use GPU acceleration.
parallel (bool, optional) – Whether to enable CPU parallelization.
- Returns:
A tuple
(new_crops, info)where:new_cropsis the list of background-corrected crop stacks,infois a dictionary containing reusable intermediate results.
The dictionary contains the following keys:
'border_medians'List of 1D arrays containing the border median value used for each crop in each input stack.
- Return type:
tuple
Notes
For each crop, the border values are collected in the following order:
left border excluding the last corner,
bottom border excluding the last corner,
right border excluding the first corner,
top border excluding the first corner.
This preserves the original logic while avoiding duplicate corner entries.
Examples
>>> import numpy as np >>> crops = [np.random.rand(4, 7, 7).astype(np.float32)] >>> new_crops, info = crop_remove_bkgd(crops) >>> len(new_crops) 1 >>> new_crops[0].shape (4, 7, 7) >>> len(info["border_medians"]) 1
>>> crops = [ ... np.random.rand(3, 9, 9).astype(np.float32), ... np.random.rand(2, 11, 11).astype(np.float32), ... ] >>> new_crops, info = crop_remove_bkgd(crops, cuda=False, parallel=True) >>> len(new_crops) 2