API Reference
Pipeline functions to run SpotMAX analysis steps in notebooks or scripts
- spotmax.pipe.filter_spots_from_features_thresholds(df_features: ~pandas.core.frame.DataFrame, features_thresholds: dict, is_spotfit=False, frame_i=0, debug=False, logger_func=<built-in function print>, verbose=True)
Filter valid spots based on features ranges
- Parameters:
df_features (pandas.DataFrame) – Pandas DataFrame with ‘spot_id’ or (‘Cell_ID’, ‘spot_id’) as index and the features as columns.
features_thresholds (dict) –
A dictionary of features and thresholds to use for filtering. The keys are the feature names that mush coincide with one of the columns’ names. The values are a tuple of (min, max) thresholds. For example, for filtering spots that have the t-statistic of the t-test spot vs reference channel > 0 and the p-value < 0.025 (i.e. spots are significantly brighter than reference channel) we pass the following dictionary:
features_thresholds = { 'spot_vs_ref_ch_ttest_pvalue': (None,0.025), 'spot_vs_ref_ch_ttest_tstat': (0, None) }
where None indicates the absence of maximum or minimum.
is_spotfit (bool, optional) – If False, features ending with ‘_fit’ will be ignored. Default is False
verbose (bool, optional) – If True, additional information text will be printed to the terminal. Default is True
debug (bool, optional) – If True, it can be used for debugging like printing additional internal steps or visualize intermediate results.
logger_func (callable, optional) – Function used to print or log process information. Default is print
- Returns:
The filtered DataFrame
- Return type:
pandas.DataFrame
- spotmax.pipe.reference_channel_quantify(ref_ch_segm, ref_ch_img, lab=None, lab_rp=None, calc_rp=True, filtering_features_thresholds=None, df_agg=None, frame_i=0, vox_to_um3=None, logger_func=<built-in function print>, verbose=True)
Calculate reference channel features and filter valid objects
- Parameters:
ref_ch_segm ((Y, X) numpy.ndarray or (Z, Y, X) numpy.ndarray of ints) – Segmentation mask of the reference channel
ref_ch_img ((Y, X) numpy.ndarray or (Z, Y, X) numpy.ndarray) – Input reference channel image.
lab ((Y, X) numpy.ndarray or (Z, Y, X) numpy.ndarray of ints, optional) – Optional input segmentation image with the masks of the objects, i.e. single cells. Default is None. Default is None
lab_rp (list of skimage.measure.RegionProperties, optional) – If not None, list of properties of objects in lab as returned by skimage.measure.regionprops(lab). If None, this will be computed with skimage.measure.regionprops(lab). Default is None
calc_rp (bool, optional) – If True, calculate additional regionprops using skimage.measure.regionprops and features.calc_additional_regionprops. Default is True
filtering_features_thresholds (dict of {'feature_name': (min_value, max_value)}, optional) – Features and their maximum and minimum values to filter valid reference channel segmented objects. An object is valid when feature_name is greater than min_value and lower than max_value. If a value is None it means there is no minimum or maximum threshold. Default is None
df_agg (pd.DataFrame, optional) – Optional input DataFrame where to insert default features. The default feautures are ref_ch_num_fragments, ref_ch_vol_vox, and ref_ch_vol_um3. Default is None
frame_i (int, optional) – Frame index in timelapse data. Default is 0
vox_to_um3 (float, optional) – Optional factor used to convert voxels to micrometer cubed (equivalent to fL). Default is None
logger_func (callable, optional) – Function used to print or log process information. Default is print
verbose (bool, optional) – If True, additional information text will be printed to the terminal. Default is True
- Returns:
df_agg (pandas.DataFrame) – DataFrame with index (‘frame_i’, ‘Cell_ID’) and three default columns where ‘Cell_ID’ is the ID of the obejcts in lab. If input df_agg is not None, these columns will be added to it. The default feautures are ref_ch_num_fragments, ref_ch_vol_vox, and ref_ch_vol_um3.
df_ref_ch (pandas.DataFrame) – DataFrame with index (‘frame_i’, ‘Cell_ID’, ‘sub_obj_id’) and all the features columns. ‘Cell_ID’ is the ID of the obejcts in lab, and ‘sub_obj_id’ is the id of each reference channel sub-object per single-cell. If input filtering_features_thresholds, is not None, the objects whose features are outside of the requested ranges are dropped from the output table.
filtered_ref_ch_segm (pandas.DataFrame) – _description_
- spotmax.pipe.reference_channel_semantic_segm(image, lab=None, gauss_sigma=0.0, keep_only_largest_obj=False, keep_objects_touching_lab_intact=False, do_remove_hot_pixels=False, lineage_table=None, do_aggregate=True, use_gpu=False, logger_func=<built-in function print>, thresholding_method=None, ridge_filter_sigmas=0, keep_input_shape=True, do_preprocess=True, return_only_segm=False, do_try_all_thresholds=True, bioimageio_model=None, bioimageio_params=None, raw_image=None, pre_aggregated=False, x_slice_idxs=None, show_progress=False)
Pipeline to segment the reference channel.
- Parameters:
image ((Y, X) numpy.ndarray or (Z, Y, X) numpy.ndarray) – Input 2D or 3D image.
lab ((Y, X) numpy.ndarray of ints or (Z, Y, X) numpy.ndarray of ints) – Optional input segmentation image with the masks of the objects, i.e. single cells. Default is None.
gauss_sigma (scalar or sequence of scalars, optional) – Standard deviation for Gaussian kernel. The standard deviations of the Gaussian filter are given for each axis as a sequence, or as a single number, in which case it is equal for all axes. If 0, no gaussian filter is applied. Default is 0.0
keep_only_largest_obj (bool, optional) – If True, keep only the largest object (determined by connected component labelling) per segmented object in lab. Default is False
keep_objects_touching_lab_intact (bool, optional) – If True, the segmented objects that are partially outside of the objects in lab are kept intact. If False, the external part is erased. Default is False
do_remove_hot_pixels (bool, optional) – If True, apply a grayscale morphological opening filter before segmenting. Opening can remove small bright spots (i.e. “salt”, or “hot pixels”) and connect small dark cracks. Default is False
lineage_table (pandas.DataFrame, optional) – Table containing parent-daughter relationships. Default is None For more details, see the parameter Table with lineage info end name at the following webpage: https://spotmax.readthedocs.io/en/latest/parameters/parameters_description.html#confval-Table-with-lineage-info-end-name
do_aggregate (bool, optional) – If True, perform segmentation on all the cells at once. Default is True
use_gpu (bool, optional) – If True, some steps will run on the GPU, potentially speeding up the computation. Default is False
logger_func (callable, optional) – Function used to print or log process information. Default is print
thresholding_method ({'threshol_li', 'threshold_isodata', 'threshold_otsu',) – ‘threshold_minimum’, ‘threshold_triangle’, ‘threshold_mean’, ‘threshold_yen’} or callable, optional Thresholding method used to obtain semantic segmentation masks of the spots. If None and do_try_all_thresholds is True, the result of every threshold method available is returned. Default is None
ridge_filter_sigmas (scalar or sequence of scalars, optional) – Sigmas used as scales of filter. If not 0, filter the image with the Sato tubeness filter. This filter can be used to detect continuous ridges, e.g. mitochondrial network. Default is 0
keep_input_shape (bool, optional) – If True, return segmentation array with the same shape of the input image. If False, output shape will depend on whether do_aggregate is True or False. Default is True
do_preprocess (bool, optional) – If True, pre-process image before segmentation using the filters ‘remove hot pixels’, ‘gaussian’, and ‘sharpen spots’ (if requested). Default is True
do_try_all_thresholds (bool, optional) – If True and thresholding_method is not None, the result of every threshold method available is returned. Default is True
return_only_segm (bool, optional) – If True, return only the result of the segmentation as numpy.ndarray with the same shape as the input image. Default is False
bioimageio_model (Cell-ACDC implementation of any BioImage.IO model, optional) – If not None, the output will include the key ‘bioimageio_model’ with the result of the segmentation using the BioImage.IO model. Default is None
bioimageio_params (_type_, optional) – Parameters used in the segment method of the bioimageio_model. Default is None
pre_aggregated (bool, optional) – If True and do_aggregate is True, run segmentation on the entire input image without aggregating segmented objects. Default is False
x_slice_idxs (list, optional) – List of indices along the x-axis of the input image (last axis) where each object in lab ends. This is useful if the input image is “aggregated” meaning that the objects in lab are concatenated along the x-axis. Default is None
raw_image ((Y, X) numpy.ndarray or (Z, Y, X) numpy.ndarray, optional) – If not None, neural network and BioImage.IO models will segment the raw image. Default is None
show_progress (bool, optional) – If True, display progressbars. Default is False
- Returns:
result – If return_only_segm is True, the output will the the numpy.ndarray with the segmentation result.
If thresholding_method is None and do_try_all_thresholds is True, the output will be a dictionary with keys {‘threshol_li’, ‘threshold_isodata’, ‘threshold_otsu’, ‘threshold_minimum’, ‘threshold_triangle’, ‘threshold_mean’, ‘threshold_yen’} and values the result of each thresholding method.
If thresholding_method is not None, the output will be a dictionary with key {‘custom’} and value the result of applying the requested thresholding_method.
If bioimageio_model is not None, the output dictionary will include the ‘bioimageio_model’ key with value the result of running the bioimageio_model requested.
The output dictionary will also include the key ‘input_image’ with value the pre-processed image.
- Return type:
dict or numpy.ndarray
- spotmax.pipe.spot_detection(image, spots_segmantic_segm=None, detection_method='peak_local_max', spot_footprint=None, spots_zyx_radii_pxl=None, return_spots_mask=False, lab=None, return_df=False, logger_func=None, validate=False, debug=False)
Detect spots and return their coordinates
- Parameters:
image ((Y, X) numpy.ndarray or (Z, Y, X) numpy.ndarray) – Input 2D or 3D image.
spots_segmantic_segm ((Y, X) numpy.ndarray of ints or (Z, Y, X) numpy.ndarray of ints, optional) – If not None and detection_method is ‘peak_local_max’, peaks will be searched only where spots_segmantic_segm > 0. Default is None
detection_method ({'peak_local_max', 'label_prediction_mask'}, optional) – Method used to detect the peaks. Default is ‘peak_local_max’ For more details, see the parameter Spots detection method at the following webpage: https://spotmax.readthedocs.io/en/latest/parameters/parameters_description.html#confval-Spots-detection-method
spot_footprint (numpy.ndarray of bools, optional) – If not None, only one peak is searched in the footprint at every point in the image. Default is None
spots_zyx_radii_pxl ((z, y, x) sequence of floats, optional) – Rough estimation of the expected spot radii in z, y, and x direction in pixels. The values are used to determine the spot footprint if spot_footprint is not provided. Default is None
return_spots_mask (bool, optional) – This is forced to be True if detection_method is equal to ‘label_prediction_mask’. If True, the second element returned will be a list of region properties (see scikit-image skimage.measure.regionprops) with an additional attribute called zyx_local_center. Default is False
lab ((Y, X) numpy.ndarray of ints or (Z, Y, X) numpy.ndarray of ints, optional) – Optional input segmentation image with the masks of the objects, i.e. single cells. It will be used to create the pandas.DataFrame with spots coordinates per object (if return_df is True). If None, it will be generated with one object covering the entire image. Default is None.
return_df (bool, optional) – If True, returns a pandas DataFrame. More details on the returned items section below. Default is False
logger_func (callable, optional) – If not None, this is the function used to print or log process information. Default is None
validate (bool, optional) – If True, it checks if there are spots detected outside of segmented objects and returns an addtional False if that happens
- Returns:
spots_coords ((N, 3) numpy.ndarray of ints) – (N, 3) array of integers where each row is the (z, y, x) coordinates of one peak. Returned only if return_df is False.
df_coords (pandas.DataFrame) – DataFrame with Cell_ID as index and columns {‘z’, ‘y’, ‘x’} with the detected spots coordinates. Returned only if return_df is True.
spots_masks (list of region properties or None) – List of spots masks as boolean arrays. None if return_spots_mask is False.
See also
- spotmax.pipe.spotfit(kernel, spots_img, df_spots, zyx_voxel_size=None, zyx_spot_min_vol_um=None, spots_zyx_radii_pxl=None, delta_tol=None, rp=None, lab=None, frame_i=0, ref_ch_mask_or_labels=None, spots_masks_check_merge=None, drop_peaks_too_close=False, return_df=False, use_gpu=False, show_progress=True, verbose=True, logger_func=<built-in function print>, custom_combined_measurements=None, max_number_pairs_check_merge=11, xy_center_half_interval_val=0.1, z_center_half_interval_val=0.2, sigma_x_min_max_expr=('0.5', 'spotsize_yx_radius_pxl'), sigma_y_min_max_expr=('0.5', 'spotsize_yx_radius_pxl'), sigma_z_min_max_expr=('0.5', 'spotsize_z_radius_pxl'), A_min_max_expr=('0.0', 'spotsize_A_max'), B_min_max_expr=('spot_B_min', 'inf'), sigma_x_guess_expr='spotsize_initial_radius_yx_pixel', sigma_y_guess_expr='spotsize_initial_radius_yx_pixel', sigma_z_guess_expr='spotsize_initial_radius_z_pixel', A_guess_expr='spotsize_A_max', B_guess_expr='spotsize_surface_median')
Run spotFIT (fitting 3D gaussian curves) and get the related features
- Parameters:
kernel (spotmax.core.SpotFIT) – Initialized SpoFIT class defined in spotmax.core.SpotFIT
spots_img ((Y, X) numpy.ndarray or (Z, Y, X) numpy.ndarray) – Input 2D or 3D image.
df_spots (pandas.DataFrame) – DataFrame with Cell_ID as index and the columns {‘z’, ‘y’, ‘x’} which are the coordinates of the spots in spots_img to fit.
zyx_voxel_size (sequence of 3 floats (z, y, x), optional) – Voxel size in μm/pixel. If None this will be initialized to (1, 1, 1). Default is None
zyx_spot_min_vol_um ((z, y, x) sequence of floats, optional) – Rough estimation of the expected spot radii in z, y, and x direction in μm. The values are used to build starting masks for the spotSIZE step. The spotSIZE step will determine the extent of each spot, i.e., the pixels that will be the input for the fitting procedure. If None this will be calculated from spots_zyx_radii_pxl and zyx_voxel_size. Default is None
spots_zyx_radii_pxl ((z, y, x) sequence of floats, optional) – Minimum distance between peaks in z, y, and x direction in pixels. Used only if drop_peaks_too_close is True. If None and drop_peaks_too_close is True then this will be calculated from zyx_spot_min_vol_um and zyx_voxel_size. Default is None
delta_tol ((z, y, x) sequence of floats, optional) – If not None, these values will be used to enlarge the segmented objects. It will enable correct fitting of those spots whose intensities bleed outside of the object (e.g., single cell). Default is None
rp (list of skimage.measure.RegionProperties, optional) – If not None, list of properties of objects in lab as returned by skimage.measure.regionprops(lab). If None, this will be computed with skimage.measure.regionprops(lab). Default is None
lab ((Y, X) numpy.ndarray of ints or (Z, Y, X) numpy.ndarray of ints, optional) – Optional input segmentation image with the masks of the objects, i.e. single cells. Default is None.
frame_i (int, optional) – Frame index in timelapse data. Default is 0
ref_ch_mask_or_labels ((Y, X) numpy.ndarray of ints or (Z, Y, X) numpy.ndarray of ints, optional) – Instance or semantic segmentation of the reference channel. Default is None
spots_masks_check_merge ((Y, X) numpy.ndarray of ints or (Z, Y, X) numpy.ndarray of ints, optional) – If not None, for each pair of touching spots in this array check if one gaussian peak fits better than two. If yes, merge the two spots before running final fitting procedure.
drop_peaks_too_close (bool, optional) – If True, when two or more peaks are within the same ellipsoid with radii = spots_zyx_radii_pxl only the brightest peak is kepts. The center of the peaks is the one determined by the fitting procedure. Default is False
return_df (bool, optional) – If True, returns a pandas DataFrame. More details on the returned items section below. Default is False
use_gpu (bool, optional) – If True, some steps will run on the GPU, potentially speeding up the computation. Default is False
show_progress (bool, optional) – If True, display progressbars. Default is False
verbose (bool, optional) – If True, additional information text will be printed to the terminal. Default is True
logger_func (callable, optional) – Function used to print or log process information. Default is print
custom_combined_measurements (dict or None, optional) – If not None, this is a dictionary of new column names as keys and mathematical expressions that combines standard single-spot features. The expression can be any text that can be evaluated by pandas.eval. More details here: https://pandas.pydata.org/docs/reference/api/pandas.eval.html
max_number_pairs_check_merge (int, optional) – If spots_masks_check_merge is not None, SpotMAX will test max_number_pairs_check_merge number of pairs to check if they require merging. The pairs are determined from all those peaks that lie on the same spot mask and are within spots_zyx_radii_pxl distance between each other. To test all pairs set this value to -1. Default is 11 (just a random lucky number :D)
xy_center_half_interval_val (float, optional) – Half interval width for bounds on x and y center coordinates during fit. Default is 0.1
z_center_half_interval_val (float, optional) – Half interval width for bounds on z center coordinate during fit. Default is 0.2
sigma_x_min_max_expr (2-tuple of str, optional) – Expressions to evaluate with pandas.eval to determine minimum and maximum values for bounds on sigma_x_fit fitting paramter. The expression can be any text that can be evaluated by pandas.eval. Default is (‘0.5’, ‘spotsize_yx_radius_pxl’). More details here: https://pandas.pydata.org/docs/reference/api/pandas.eval.html
sigma_y_min_max_expr (2-tuple of str, optional) – Expressions to evaluate with pandas.eval to determine minimum and maximum values for bounds on sigma_y_fit fitting paramter. The expression can be any text that can be evaluated by pandas.eval. Default is (‘0.5’, ‘spotsize_yx_radius_pxl’). More details here: https://pandas.pydata.org/docs/reference/api/pandas.eval.html Default is (‘0.5’, ‘spotsize_yx_radius_pxl’).
sigma_z_min_max_expr (2-tuple of str, optional) – Expressions to evaluate with pandas.eval to determine minimum and maximum values for bounds on sigma_z_fit fitting paramter. The expression can be any text that can be evaluated by pandas.eval. Default is (‘0.5’, ‘spotsize_z_radius_pxl’). More details here: https://pandas.pydata.org/docs/reference/api/pandas.eval.html
A_min_max_expr (2-tuple of str, optional) – Expressions to evaluate with pandas.eval to determine minimum and maximum values for bounds on A_fit (peak amplitude) fitting paramter. The expression can be any text that can be evaluated by pandas.eval. Default is (‘0.0’, ‘spotsize_A_max’). More details here: https://pandas.pydata.org/docs/reference/api/pandas.eval.html
B_min_max_expr (2-tuple of str, optional) – Expressions to evaluate with pandas.eval to determine minimum and maximum values for bounds on B_fit (background) fitting paramter. The expression can be any text that can be evaluated by pandas.eval. Default is (‘spot_B_min’, ‘inf’). More details here: https://pandas.pydata.org/docs/reference/api/pandas.eval.html
sigma_x_guess_expr (str, optional) – Expressions to evaluate with pandas.eval to determine the initial guess for the sigma_x_fit fitting paramter. The expression can be any text that can be evaluated by pandas.eval. Default is ‘spotsize_initial_radius_yx_pixel’. More details here: https://pandas.pydata.org/docs/reference/api/pandas.eval.html
sigma_y_guess_expr (str, optional) – Expressions to evaluate with pandas.eval to determine the initial guess for the sigma_y_fit fitting paramter. The expression can be any text that can be evaluated by pandas.eval. Default is ‘spotsize_initial_radius_yx_pixel’. More details here: https://pandas.pydata.org/docs/reference/api/pandas.eval.html
sigma_z_guess_expr (str, optional) – Expressions to evaluate with pandas.eval to determine the initial guess for the sigma_z_fit fitting paramter. The expression can be any text that can be evaluated by pandas.eval. Default is ‘spotsize_initial_radius_z_pixel’. More details here: https://pandas.pydata.org/docs/reference/api/pandas.eval.html
A_guess_expr (str, optional) – Expressions to evaluate with pandas.eval to determine the initial guess for the A_fit (amplitude) fitting paramter. The expression can be any text that can be evaluated by pandas.eval. Default is ‘spotsize_A_max’. More details here: https://pandas.pydata.org/docs/reference/api/pandas.eval.html
B_guess_expr (str, optional) – Expressions to evaluate with pandas.eval to determine the initial guess for the B_fit (background) fitting paramter. The expression can be any text that can be evaluated by pandas.eval. Default is ‘spotsize_surface_median’. More details here: https://pandas.pydata.org/docs/reference/api/pandas.eval.html
- Returns:
keys (list of 2-tuple (int, int)) – List of keys that can be used to concatenate the dataframes with pandas.concat(dfs_spots_spotfit, keys=keys, names=[‘frame_i’, ‘Cell_ID’]) Returned only if return_df is False
dfs_spots_spotfit (list of pandas.DataFrames) – List of DataFrames with additional spotFIT features columns for each frame and ID of the segmented objects in lab. If drop_peaks_too_close is True, each DataFrame in this list will contain only the valid spots. Returned only if return_df is False
dfs_spots_spotfit_iter0 (list of pandas.DataFrames) – List of DataFrames with additional spotFIT features columns for each frame and ID of the segmented objects in lab. No matter the value of drop_peaks_too_close, each DataFrame in this list will contain all the input spots. Returned only if return_df is False
df_spotfit (pandas.DataFrame) – DataFrame with Cell_ID as index and all the spotFIT features as columns. If drop_peaks_too_close is True this DataFrame will contain only valid spots. Returned only if return_df is True
df_spotfit_iter0 (pandas.DataFrame) – DataFrame with Cell_ID as index and all the spotFIT features as columns. No matter the value of drop_peaks_too_close this DataFrame will contain all the input spots. Returned only if return_df is True
See also
- spotmax.pipe.spots_calc_features_and_filter(image, spots_zyx_radii_pxl, df_spots_coords, frame_i=0, sharp_spots_image=None, lab=None, rp=None, gop_filtering_thresholds=None, delta_tol=None, raw_image=None, ref_ch_mask_or_labels=None, ref_ch_img=None, keep_only_spots_in_ref_ch=False, remove_spots_in_ref_ch=False, use_spots_segm_masks=False, min_size_spheroid_mask=None, zyx_voxel_size=None, optimise_for_high_spot_density=False, dist_transform_spheroid=None, local_background_ring_width='5 pixel', get_backgr_from_inside_ref_ch_mask=False, custom_combined_measurements=None, show_progress=True, verbose=True, logger_func=<built-in function print>, logger_warning_report=<built-in function print>)
Calculate spots features and filter valid spots based on gop_filtering_thresholds.
- Parameters:
image ((Y, X) numpy.ndarray or (Z, Y, X) numpy.ndarray) – Input 2D or 3D image.
spots_zyx_radii_pxl ((z, y, x) sequence of floats, optional) – Rough estimation of the expected spot radii in z, y, and x direction in pixels. The values are used to build the ellipsoid mask centered at each spot. The volume of the ellipsoid is then used for those aggregated metrics like the mean intensity in the spot.
df_spots_coords (pandas.DataFrame) – DataFrame with Cell_ID as index and the columns {‘z’, ‘y’, ‘x’} which are the coordinates of the spots in image.
frame_i (int, optional) – Frame index in timelapse data. Default is 0
sharp_spots_image ((Y, X) numpy.ndarray or (Z, Y, X) numpy.ndarray, optional) – Optional image that was filtered to enhance the spots (e.g., using spotmax.filters.DoG_spots). This image will be used for those features that requires comparing the spot’s signal to a reference signal (background or reference channel). If None, image will be used instead. Default is None
lab ((Y, X) numpy.ndarray of ints or (Z, Y, X) numpy.ndarray of ints, optional) – Optional input segmentation image with the masks of the objects, i.e. single cells. If None, it will be generated with one object covering the entire image. Default is None.
rp (list of skimage.measure.RegionProperties, optional) – If not None, list of properties of objects in lab as returned by skimage.measure.regionprops(lab). If None, this will be computed with skimage.measure.regionprops(lab). Default is None
gop_filtering_thresholds (dict of {'feature_name': (min_value, max_value)}, optional) – Features and their maximum and minimum values to filter valid spots. A spot is valid when feature_name is greater than min_value and lower than max_value. If a value is None it means there is no minimum or maximum threshold. Default is None
delta_tol ((z, y, x) sequence of floats, optional) – If not None, these values will be used to enlarge the segmented objects. It will prevent clipping the spots masks for those spots whose intensities bleed outside of the object (e.g., single cell). Default is None
raw_image ((Y, X) numpy.ndarray or (Z, Y, X) numpy.ndarray, optional) – Optional image to calculate features from. The name of these features will have the text ‘_raw_’. Default is None
ref_ch_mask_or_labels ((Y, X) numpy.ndarray of ints or (Z, Y, X) numpy.ndarray of ints, optional) – Instance or semantic segmentation of the reference channel. If not None, this is used to calculate the background intensity inside the segmented object from lab but outside of the reference channel mask. Default is None
ref_ch_img ((Y, X) numpy.ndarray or (Z, Y, X) numpy.ndarray, optional) – Reference channel image. Default is None
keep_only_spots_in_ref_ch (bool, optional) – If True, drops the spots that are outside of the reference channel mask. Default is False
remove_spots_in_ref_ch (bool, optional) – If True, removes the spots that are inside the reference channel mask. Default is False
use_spots_segm_masks (bool, optional) – If True and df_spots_coords has a column called ‘spot_maks’ with one spot mask for each spot then min_size_spheroid_mask is ignored and the spot mask from df_spots_coords will be used. Default is False
min_size_spheroid_mask ((M, N) numpy.ndarray or (K, M, N) numpy.ndarray or bools, optional) – Spheroid mask used to calculate those aggregated features like the mean intensity in each spot. If this value is None, it will be created from spots_zyx_radii_pxl. Note that if use_spots_segm_masks is True, this parameter might be ignored. Default is None
zyx_voxel_size ((z, y, x) sequence) – Voxel size in z-, y-, and x- directions in μm/pixel. If None, this will be initialize to [1, 1, 1]. Default is None
optimise_for_high_spot_density (bool, optional) – If True and dist_transform_spheroid is None, then dist_transform_spheroid will be initialized with the euclidean distance transform of min_size_spheroid_mask.
dist_transform_spheroid ((M, N) numpy.ndarray or (K, M, N) numpy.ndarray of floats, optional) – Optional probability map that will be multiplicated to each spot’s intensities. An example is the euclidean distance tranform (normalised to the range 0-1). This is useful to reduce the influence of bright neighbouring spots on dimmer spots since the intensities of the bright spot can bleed into the edges of the dimmer spot skewing its metrics like the mean intensity. If None and optimise_for_high_spot_density is True, this will be initialized with the euclidean distance transform of min_size_spheroid_mask. Default is None
local_background_ring_width ('<value> pixel' or '<value> micrometre') – Width of the ring around each spot used to determine the local effect sizes. It can be specified in pixel or micrometre, e.g. ‘5 pixel’ or ‘0.4 micrometre’. If the unit is ‘micrometre’, then the value will be converted to ‘pixel’ using zyx_voxel_size[-1] and rounded to the nearest integer. Default is ‘5 pixel’
get_backgr_from_inside_ref_ch_mask (bool, optional) – If True, the background will be determined from the pixels that are outside of the spots, but inside the reference channel mask. Default is False
custom_combined_measurements (dict or None, optional) – If not None, this is a dictionary of new column names as keys and mathematical expressions that combines standard single-spot features. The expression can be any text that can be evaluated by pandas.eval. More details here: https://pandas.pydata.org/docs/reference/api/pandas.eval.html
show_progress (bool, optional) – If True, display progressbars. Default is False
verbose (bool, optional) – If True, additional information text will be printed to the terminal. Default is True
logger_func (callable, optional) – Function used to print or log process information. Default is print
logger_warning_report (callable, optional) – Additional function used by the SpotMAX cli Kernel to log warnings in the report file. Default is print
- Returns:
keys (list of 2-tuple (int, int)) – List of keys that can be used to concatenate the dataframes with pandas.concat(dfs_spots_gop, keys=keys, names=[‘frame_i’, ‘Cell_ID’])
dfs_spots_det (list of pandas.DataFrames) – List of DataFrames with the features columns for each frame and ID of the segmented objects in lab
dfs_spots_gop (list of pandas.DataFrames) – Same as dfs_spots_det but with only the valid spots
See also
- spotmax.pipe.spots_semantic_segmentation(image, lab=None, gauss_sigma=0.0, spots_zyx_radii_pxl=None, do_sharpen=False, do_remove_hot_pixels=False, lineage_table=None, do_aggregate=True, thresh_only_inside_objs_intens=True, min_spot_mask_size=5, keep_objects_touching_lab_intact=True, use_gpu=False, logger_func=<built-in function print>, thresholding_method=None, keep_input_shape=True, nnet_model=None, nnet_params=None, nnet_input_data=None, return_nnet_prediction=False, bioimageio_model=None, bioimageio_params=None, spotiflow_model=None, spotiflow_params=None, do_preprocess=True, do_try_all_thresholds=True, return_only_segm=False, pre_aggregated=False, x_slice_idxs=None, raw_image=None)
Pipeline to perform semantic segmentation on the spots channel, i.e., determine the areas where spot will be detected.
- Parameters:
image ((Y, X) numpy.ndarray or (Z, Y, X) numpy.ndarray) – Input 2D or 3D image.
lab ((Y, X) numpy.ndarray of ints or (Z, Y, X) numpy.ndarray of ints, optional) – Optional input segmentation image with the masks of the objects, i.e. single cells. Spots will be detected only inside each object. If None, detection will be performed on the entire image. Default is None.
gauss_sigma (scalar or sequence of scalars, optional) – Standard deviation for Gaussian kernel. The standard deviations of the Gaussian filter are given for each axis as a sequence, or as a single number, in which case it is equal for all axes. If 0, no gaussian filter is applied. Default is 0.0
spots_zyx_radii_pxl ((z, y, x) sequence of floats, optional) – Rough estimation of the expected spot radii in z, y, and x direction in pixels. The values are used to determine the sigmas used in the difference-of-gaussians filter that enhances spots-like structures. If None, no filter is applied. Default is None
do_sharpen (bool, optional) – If True and spots_zyx_radii_pxl is not None, applies a difference-of-gaussians (DoG) filter before segmenting. This filter enhances spots-like structures and it usually improves detection. Default is False. For more details, see the parameter Sharpen spots signal prior detection at the following webpage: https://spotmax.readthedocs.io/en/latest/parameters/parameters_description.html#confval-Sharpen-spots-signal-prior-detection
do_remove_hot_pixels (bool, optional) – If True, apply a grayscale morphological opening filter before segmenting. Opening can remove small bright spots (i.e. “salt”, or “hot pixels”) and connect small dark cracks. Default is False
lineage_table (pandas.DataFrame, optional) – Table containing parent-daughter relationships. Default is None For more details, see the parameter Table with lineage info end name at the following webpage: https://spotmax.readthedocs.io/en/latest/parameters/parameters_description.html#confval-Table-with-lineage-info-end-name
do_aggregate (bool, optional) – If True, perform segmentation on all the cells at once. Default is True
thresh_only_inside_objs_intens (bool, optional) – If True, use only the intensities from inside the segmented objects (in lab). Default is False
min_spot_mask_size (int, optional) – Minimum size (in pixels) of the spots masks. Masks with size < min_spot_mask_size will be removed. Default is 5.
keep_objects_touching_lab_intact (bool, optional) – If True, objects that are partially touching any of the segmentation masks present in lab will be entirely kept. If False, the part of these objects that is outside of the segmentation masks will be removed. Default is True
use_gpu (bool, optional) – If True, some steps will run on the GPU, potentially speeding up the computation. Default is False
logger_func (callable, optional) – Function used to print or log process information. Default is print
thresholding_method ({'threshol_li', 'threshold_isodata', 'threshold_otsu',) – ‘threshold_minimum’, ‘threshold_triangle’, ‘threshold_mean’, ‘threshold_yen’} or callable, optional Thresholding method used to obtain semantic segmentation masks of the spots. If None and do_try_all_thresholds is True, the result of every threshold method available is returned. Default is None
keep_input_shape (bool, optional) – If True, return segmentation array with the same shape of the input image. If False, output shape will depend on whether do_aggregate is True or False. Default is True
nnet_model (Cell-ACDC segmentation model class, optional) – If not None, the output will include the key ‘neural_network’ with the result of the segmentation using the neural network model. Default is None
nnet_params (dict with 'segment' key, optional) – Parameters used in the segment method of the nnet_model. Default is None
nnet_input_data (numpy.ndarray or sequence of arrays, optional) – If not None, run the neural network on this data and not on the pre-processed input image. Default is None
return_nnet_prediction (bool, optional) – If True, include the key ‘neural_network_prediciton’ in the returned dictionary. Default is False
bioimageio_model (Cell-ACDC implementation of any BioImage.IO model, optional) – If not None, the output will include the key ‘bioimageio_model’ with the result of the segmentation using the BioImage.IO model. Default is None
bioimageio_params (dict with 'segment' key, optional) – Parameters used in the segment method of the bioimageio_model. Default is None
spotiflow_model (Cell-ACDC implementation of Spotiflow, optional) – If not None, the output will include the key ‘spotiflow’ with the result of the segmentation using Spotiflow. Default is None
spotiflow_params (dict with 'segment' key, optional) – Parameters used in the segment method of the spotiflow_model. Default is None
do_preprocess (bool, optional) – If True, pre-process image before segmentation using the filters ‘remove hot pixels’, ‘gaussian’, and ‘sharpen spots’ (if requested). Default is True
do_try_all_thresholds (bool, optional) – If True and thresholding_method is not None, the result of every threshold method available is returned. Default is True
return_only_segm (bool, optional) – If True, return only the result of the segmentation as numpy.ndarray with the same shape as the input image. Default is False
pre_aggregated (bool, optional) – If True and do_aggregate is True, run segmentation on the entire input image without aggregating segmented objects. Default is False
x_slice_idxs (list, optional) – List of indices along the x-axis of the input image (last axis) where each object in lab ends. This is useful if the input image is “aggregated” meaning that the objects in lab are concatenated along the x-axis. Default is None
raw_image ((Y, X) numpy.ndarray or (Z, Y, X) numpy.ndarray, optional) – If not None, neural network and BioImage.IO models will segment the raw image. Default is None
- Returns:
result – If return_only_segm is True, the first value of the output will be the numpy.ndarray with the segmentation result. Note that, in this case, if nnet_model is not None and nnet_params[‘save_prediction_map’] is True the second value of the output will be the prediction map from the output of running nnet_model.
If thresholding_method is None and do_try_all_thresholds is True, the output will be a dictionary with keys {‘threshol_li’, ‘threshold_isodata’, ‘threshold_otsu’, ‘threshold_minimum’, ‘threshold_triangle’, ‘threshold_mean’, ‘threshold_yen’} and values the result of each thresholding method.
If thresholding_method is not None, the output will be a dictionary with one key {‘custom’} and the result of applying the requested thresholding_method.
If nnet_model is not None, the output dictionary will include the ‘neural_network’ key with value the result of running the nnet_model requested.
If return_nnet_prediction is True and nnet_model is not None, the output dictionary will include the ‘neural_network_prediciton’ key with value the prediction map output of nnet_model.
If bioimageio_model is not None, the output dictionary will include the ‘bioimageio_model’ key with value the result of running the bioimageio_model requested.
If spotiflow_model is not None, the output dictionary will include the ‘spotiflow’ key with value the result of running the spotiflow_model requested.
The output dictionary will also include the key ‘input_image’ with value the pre-processed image.
- Return type:
dict or numpy.ndarray