Labels

Fill in a module description here

source

compute_mfi

 compute_mfi (cell_mask, channel1, channel2=None, channel3=None,
              nuclear_mask=None)

Fast computation of mean fluorescence intensity (MFI) per cell and per nucleus using vectorized numpy.bincount operations.

Type Default Details
cell_mask 2D int array Label mask of cells (0 = background).
channel1 2D float array First fluorescence channel.
channel2 NoneType None Second fluorescence channel.
channel3 NoneType None Third fluorescence channel.
nuclear_mask NoneType None Label mask of nuclei (0 = background). If provided, nuclei MFI is computed.
Returns pd.DataFrame DataFrame with columns:
- region: ‘cell’ or ‘nucleus’
- label: integer label
- mfi_ch1, mfi_ch2, mfi_ch3 (if provided)
/opt/hostedtoolcache/Python/3.10.18/x64/lib/python3.10/site-packages/fastcore/docscrape.py:230: UserWarning: Unknown section Parameters:
  else: warn(msg)

source

plot_channel_mask

 plot_channel_mask (mask, channel1, channel2=None, channel3=None,
                    save_path=None, nuclear_mask=None)

*Plot up to three fluorescence channels with cell and nuclear mask overlays.

If only channel1 is provided, uses Spectral colormap. If channel2 and channel3 are provided, displays: - channel1 in green - channel2 in magenta - channel3 in yellow*


source

plot_label_mask

 plot_label_mask (mask, cell_type_map=None, type_colors=None,
                  default_color=(0, 0, 0), outline_color='black',
                  seed=None, save_path=None, nuclear_mask=None)

Plot a label mask coloring cells based on their assigned type. Unspecified or ‘other’ cells remain in default_color (black by default). Adds outlines for both cell and nuclear masks in specified color.


source

expand_with_cap

 expand_with_cap (label_image:numpy.ndarray, spacing:Tuple[float,float],
                  fixed_expand:float=10.0, max_area_ratio:float=1.5)

Expand labeled nuclei by up to a fixed radius, capped by max area ratio.

Type Default Details
label_image ndarray 2D integer array of labels (0=background).
spacing Tuple Physical size (µm) of each pixel along (row, column) axes.
fixed_expand float 10.0 Nominal expansion radius in µm. Default is 10.0.
max_area_ratio float 1.5 Maximum allowed area increase factor. Default is 1.5.
Returns ndarray Dilated label image, where each pixel is assigned to the nearest
original label if within its per-pixel cap.

source

get_physical_size

 get_physical_size (filename:str, verbose:bool=False)

Compute the physical pixel size (µm/px) from a TIFF file’s resolution metadata.

Type Default Details
filename str Path to the TIFF file.
verbose bool False If True, print resolution details. Default is False.
Returns float Physical size of a pixel in microns. Raises if pixels are non-square.

source

plot_outlines

 plot_outlines (mask:numpy.ndarray, image:numpy.ndarray,
                save_path:str=None)

Overlay nuclear outlines from a mask onto an image and optionally save the result.

Type Default Details
mask ndarray 2D array of integer labels where nonzero values indicate nuclei.
image ndarray Grayscale image array of the same shape as mask.
save_path str None File path in which to save the outline image. If None, no file is written.
Returns matplotlib.figure.Figure Figure object containing the outline overlay.

source

predict

 predict (img_list:list, use_gpu:bool, model_path:str=None,
          diameters:float=None, cellpose_param:tuple=(0.4, 0.0))

*Run a Cellpose segmentation model to generate segmentation masks for a list of images.

This function loads a Cellpose model and applies it to each image in the provided list. If a custom model path is given, it uses that pretrained model; otherwise, it defaults to the nuclei segmentation model. The segmentation thresholds can be controlled via cellpose_param, and an estimated diameter of the objects (nuclei) to segment can be provided when using the default model.*

Type Default Details
img_list list A list of image arrays (grayscale) to segment.
use_gpu bool Indicates whether to use GPU acceleration for model evaluation.
model_path str None Path to a custom pretrained Cellpose model. If None, the default nuclei model is used.
diameters float None Estimated diameter (in pixels) of the objects (nuclei) to segment. This is used only when model_path is None.
cellpose_param tuple (0.4, 0.0) A tuple (flow_threshold, cellprob_threshold) to control the Cellpose evaluation parameters.
Defaults to (0.4, 0.0).
Returns ndarray Array of shape (N, H, W) containing the segmentation masks for each input image.