fishdist.fish_analysis_pipeline

apply_affine_trafo_to_image(image, affine_trafo_matrix)

Apply a 3D affine transformation to an image using the provided affine transformation matrix.

Parameters:
  • image (ndarray) –

    3D image array to be transformed. Expected shape is (Z, Y, X) unless your underlying transform function requires otherwise.

  • affine_trafo_matrix (ndarray) –

    4×4 affine transformation matrix (or compatible format) used to transform the image.

Returns:
  • np.ndarray: The transformed image.

Example
>>> import numpy as np
>>> image = np.random.rand(10, 100, 100)
>>> affine = np.eye(4)
>>> transformed = apply_affine_trafo_to_image(image, affine)
>>> transformed.shape
(10, 100, 100)

apply_affine_transform_to_all_images(paths, root_folder_path_to_affine_trafo_matrix, table_name_prefix='points_n_distances3D', ch1=1, ch2=2, atol=1e-06)

Apply a precomputed affine transformation to all images and recompute corrected distances.

This function
  • Loads the affine transformation matrix and voxel size
  • Verifies voxel size matches the images
  • Applies the affine transformation to the first set of coordinates in a table
  • Computes distances between transformed and original second coordinates
  • Saves the corrected coordinates and distances to a new table
  • Plots the distance distribution after correction
Parameters:
  • paths (list[str]) –

    List of dataset paths containing 'FISH.db'.

  • root_folder_path_to_affine_trafo_matrix (str) –

    Path where affine matrix and voxel size are saved. Files should be named as 'ch{ch1}_ch{ch2}_acc.npy' and 'ch{ch1}_ch{ch2}_voxel_size.npy'.

  • table_name_prefix (str, default: 'points_n_distances3D' ) –

    Prefix of the table in each FISH.db to which the affine transformation will be applied. The actual table name will be constructed as f'{table_name_prefix}_ch{ch1}_ch{ch2}_only_in_nuclei'. Defaults to 'points_n_distances3D'.

  • ch1 (int, default: 1 ) –

    First channel number. Defaults to 1.

  • ch2 (int, default: 2 ) –

    Second channel number. Defaults to 2.

  • atol (float, default: 1e-06 ) –

    Absolute tolerance when comparing voxel sizes. Defaults to 1e-6.

Returns:
  • None

Example
paths = ['sample1.tif', 'sample2.tif']
root_folder = 'correction_results'
apply_affine_transform_to_all_images(paths, root_folder, ch1=1, ch2=2)

compute_affine_transform_for_images(paths, correction_matrix_save_path, ch1=1, ch2=2, db_to_read='points_n_distances3D', USE_AFFINE_TRAFO_WITH_SHEAR=True, use_median_n_IQR_filtering_of_coords=True)

Compute and save a global affine transformation matrix for multiple images based on spot coordinates.

Parameters:
  • paths (list[str]) –

    List of file paths to images.

  • correction_matrix_save_path (str) –

    Directory where the affine matrix and plots will be saved.

  • ch1 (int, default: 1 ) –

    First channel number. Defaults to 1.

  • ch2 (int, default: 2 ) –

    Second channel number. Defaults to 2.

  • db_to_read (str, default: 'points_n_distances3D' ) –

    Database table prefix to read spot coordinates from. The actual table name will be constructed as f'{db_to_read}_ch{ch1}_ch{ch2}_only_in_nuclei'. Defaults to 'points_n_distances3D'.

  • USE_AFFINE_TRAFO_WITH_SHEAR (bool, default: True ) –

    Whether to include shear in the affine transformation. Defaults to True.

  • use_median_n_IQR_filtering_of_coords (bool, default: True ) –

    Whether to filter coordinate pairs using median ± IQR. Defaults to True.

Returns:
  • None

Example
paths = ['sample1.tif', 'sample2.tif']
correction_path = 'correction_results'
compute_affine_transform_for_images(paths, correction_path, ch1=1, ch2=2)

detect_spots(detected_spot_binary_image, original_image, validity_mask=None, area_threshold=None, minimal_diameter=None, smart_detect_spots=False, CUBOID_RADIUS=None, gaussian_fit_3D=False, voxel_size=None, real_spot_size=None, gaussian_fit_mode='all')

Detect spot centroids in an image with optional filtering, ROI expansion, and sub-pixel Gaussian refinement.

Parameters:
  • detected_spot_binary_image (ndarray) –

    Binary image where non-zero pixels indicate detected spots.

  • original_image (ndarray) –

    Original intensity image used for centroid computation and refinement.

  • validity_mask (ndarray or None, default: None ) –

    Optional binary mask used to score spots based on spatial validity. Defaults to None.

  • area_threshold (int or None, default: None ) –

    Minimum area a detected spot must have to be kept. Defaults to None.

  • minimal_diameter (int or sequence or None, default: None ) –

    Minimum diameter to which planar or point ROIs are extended. Defaults to None.

  • smart_detect_spots (bool, default: False ) –

    Whether to use a smart validation-based spot detection strategy. Defaults to False.

  • CUBOID_RADIUS (int or sequence or None, default: None ) –

    Radius of a cuboid region used to refine centroid computation. Defaults to None.

  • gaussian_fit_3D (bool, default: False ) –

    Whether to perform 3D Gaussian fitting for sub-pixel localization. Defaults to False.

  • voxel_size (sequence or None, default: None ) –

    Physical voxel size used to scale Gaussian fitting. Defaults to None.

  • real_spot_size (sequence or None, default: None ) –

    Explicit spot size used for Gaussian fitting. Defaults to None.

  • gaussian_fit_mode (str, default: 'all' ) –

    Mode for Gaussian fitting ("all" or selective fitting). Defaults to "all".

Returns:
  • np.ndarray: Array of detected spot coordinates, optionally augmented with validity scores

  • and Gaussian fit success flags.

Example

detect_spots_and_nuclei(paths, ch_nuclei=0, first_spot_channel=1, second_spot_channel=-1, area_threshold=None, channels_to_blur=None, blur_mode='recursive2D', threshold_nuclei=0.5, threshold_spot=0.5)

Detect 3D nuclei and spot coordinates from deep-learning probability maps.

Parameters:
  • paths (list[str]) –

    List of input image paths.

  • ch_nuclei (int or None, default: 0 ) –

    Channel index of nuclei in the original image. If None, nuclei detection on the raw image is skipped. Defaults to 0.

  • spot_channels (list[int]) –

    List of channel indices for spot detection. Defaults to [1, 2].

  • area_threshold (int or None, default: None ) –

    Minimum ROI area threshold passed to detect_spots. Defaults to None.

  • channels_to_blur (list[int] or None, default: None ) –

    Channels in the raw image to blur before detection. Defaults to None.

  • blur_mode (str, default: 'recursive2D' ) –

    Blur mode for 3D smoothing. Defaults to "recursive2D".

  • threshold_nuclei (float, default: 0.5 ) –

    Binarization threshold for the deep-learning probability map of the nuclear channel. Defaults to 0.5.

  • threshold_spot (float, default: 0.5 ) –

    Binarization threshold for the deep-learning probability map of spot channels. Defaults to 0.5.

Returns:
  • None

    Detected nuclei and spot coordinates are written to the database.

Example
paths = ["img1.tif", "img2.tif"]
detect_spots_and_nuclei(
    paths,
    ch_nuclei=0,
    spot_channels=[1, 2, 3, 4],
    area_threshold=10,
    channels_to_blur=[0, 1],
    blur_mode="recursive2D",
    threshold_nuclei=0.5,
    threshold_spot=0.6
)

do_controls_for_easy_check(paths, ch1=1, ch2=2, ch_nuclei=0)

Generate quick visual control images for multi-channel datasets.

For each dataset path, the function loads specified channels, processes them (optional inversion, normalization, dilation), computes merged 3D stacks and maximum projections, and saves reduced-size versions for visual inspection.

Parameters:
  • paths (list[str]) –

    List of dataset paths to process.

  • ch1 (int, default: 1 ) –

    First channel index. Defaults to 1.

  • ch2 (int, default: 2 ) –

    Second channel index. Defaults to 2.

  • ch_nuclei (int, default: 0 ) –

    Nuclei channel index. Defaults to 0.

Returns:
  • None

    The function saves control images to disk for each dataset.

Example
paths = ["sample_01.tif", "sample_02.tif"]
do_controls_for_easy_check(paths, ch1=1, ch2=2, ch_nuclei=0)

extend_ROIS_to_specified_diameter(regions, EXTEND_PLANAR_OR_POINT_TO_DIAMETER, bounds)

Extend regions of interest (ROIs) to ensure that each dimension of the region's bounding box has at least a specified diameter.

This is useful when single points or very small planar ROIs need to be expanded to a minimum size (e.g., for morphological consistency or for intensity measurements in 3D volumes).

Parameters:
  • regions (list) –

    List of RegionProperties objects or arrays of coordinates. Each element is either: - a skimage.measure.RegionProperties instance, or - an ndarray of shape (N_points, N_dims).

  • EXTEND_PLANAR_OR_POINT_TO_DIAMETER (int, sequence, or None) –

    Minimum desired diameter for each dimension. If None, 0, or sums to zero, regions are returned unchanged. Passed through _create_n_dimensional_array to normalize shape.

  • bounds (ndarray) –

    Array of per-dimension [min, max] bounds used to clip final coordinates, typically from the size of the 3D image.

Returns:
  • list

    A list of coordinate arrays (or RegionProperties-like data), with regions expanded if needed.

Example
>>> regions = [np.array([[2, 2, 2]])]
>>> bounds = np.array([[0, 10], [0, 10], [0, 10]])
>>> extend_ROIS_to_specified_diameter(regions, 3, bounds)
[array([[1, 1, 1],
       [1, 1, 2],
       [1, 1, 3],
       [1, 2, 1],
       [1, 2, 2],
       [1, 2, 3],
       [1, 3, 1],
       [1, 3, 2],
       [1, 3, 3],
       [2, 1, 1],
       [2, 1, 2],
       [2, 1, 3],
       [2, 2, 1],
       [2, 2, 2],
       [2, 2, 3],
       [2, 3, 1],
       [2, 3, 2],
       [2, 3, 3],
       [3, 1, 1],
       [3, 1, 2],
       [3, 1, 3],
       [3, 2, 1],
       [3, 2, 2],
       [3, 2, 3],
       [3, 3, 1],
       [3, 3, 2],
       [3, 3, 3]])]

finalize_quantifications_n_pairing(path_to_db, first_spot_channel=1, second_spot_channels=-1, PAIRING_THRESHOLD=250, voxel_conversion_factor=None, ONLY_DETECT_SPOTS_IN_NUCLEI=True)

Compute spot pairing across channels and save distance statistics to a database.

Parameters:
  • path_to_db (str) –

    Path to the SQLite database.

  • first_spot_channel (int, default: 1 ) –

    Channel index for the reference spot channel.

  • second_spot_channels (list[int] or None, default: -1 ) –

    List of channel indices for spot channels to pair with the first_spot_channel. If None, all channels except nuclei and first_spot_channel are used.

  • PAIRING_THRESHOLD (float, default: 250 ) –

    Maximum allowed pairing distance in pixels (unless a voxel conversion factor is provided). Defaults to 250.

  • voxel_conversion_factor (tuple or list or None, default: None ) –

    Optional (z, y, x) conversion factors used to convert pixel distances to physical units (e.g., micrometers). Defaults to None.

  • ONLY_DETECT_SPOTS_IN_NUCLEI (bool, default: True ) –

    Whether to restrict pairing to spots detected inside nuclei and compute penetrance statistics. Defaults to True.

Returns:
  • None

    Results are written to the database and histogram files are saved

  • to disk.

Example
path_to_db = "experiment/FISH.db"
finalize_quantifications_n_pairing(
    path_to_db,
    first_spot_channel=1,
    second_spot_channels=[2, 3, 4],
    PAIRING_THRESHOLD=200,
    voxel_conversion_factor=(0.3, 0.1, 0.1),
    ONLY_DETECT_SPOTS_IN_NUCLEI=True
)

find_spots_in_nuclei(spot_ROIs, nuclear_mask)

Compute the fraction of each spot ROI that overlaps with a nuclear mask.

Each spot is represented either as a RegionProperties object or as an array of coordinates. The nuclear mask is a binarized image where non-zero pixels indicate nuclear regions.

Parameters:
  • spot_ROIs (list) –

    List of RegionProperties or ndarray of coordinates (shape: N_points x N_dims).

  • nuclear_mask (ndarray or None) –

    Binary mask of nuclei. Non-zero pixels indicate nuclear regions. If None, all spots are considered outside nuclei.

Returns:
  • list of float: Fraction of each spot contained within the nuclear mask. Value is between 0 (no overlap) and 1 (fully inside nuclei).

Example
>>> spot_ROIs = [np.array([[0,0],[0,1]]), np.array([[5,5]])]
>>> nuclear_mask = np.zeros((10,10), dtype=int)
>>> nuclear_mask[0,0] = 1
>>> find_spots_in_nuclei(spot_ROIs, nuclear_mask)
[0.5, 0.0]


get_bounds_for_nd_coords(nd_coords)

Compute per-dimension minimum and maximum bounds for an array of N-dimensional coordinates.

Parameters:
  • nd_coords (array - like or ndarray) –

    An array of shape (N_points, N_dims), where each row is a coordinate and each column corresponds to a dimension.

Returns:
  • np.ndarray: Array of shape (N_dims, 2), where each row contains [min, max] for the corresponding dimension.

Example
>>> import numpy as np
>>> coords = np.array([[0, 1, 2],
...                    [5, -1, 3],
...                    [2, 4, 0]])
>>> get_bounds_for_nd_coords(coords)
array([[ 0,  5],
       [-1,  4],
       [ 0,  3]])


get_nb_channels(db_path)

Retrieves the number of channels from an SQLite database file.

Parameters:
  • db_path (str) –

    The path to the SQLite database file.

Returns:
  • int or None: The number of channels if found, None otherwise.

Examples:

If the 'nb_channels' table in the database contains the value 3, then:

get_nb_channels('example.db')
3

If the 'nb_channels' table does not exist in the database file:

get_nb_channels('example.db')
None

If the database file does not exist:

get_nb_channels('nonexistent.db')
None

get_spot_channels(image_shape, ch_nuclei, first_spot_channel, second_spot_channel=None)

Returns a list of spot channel indices to use for image analysis.

If second_spot_channel is None, all channels except ch_nuclei and first_spot_channel are included. If second_spot_channel is an integer, only that channel is included. If second_spot_channel is a list, that list is returned directly.

Parameters:
  • image_shape (tuple) –

    Shape of the image as (z, h, w, c).

  • ch_nuclei (int) –

    Index of the nucleus channel.

  • first_spot_channel (int) –

    Index of the first spot channel.

  • second_spot_channel (int or list or None, default: None ) –

    Index of the second spot channel. If None, all channels except ch_nuclei and first_spot_channel are used. If an integer, only that channel is used. If a list, that list is returned directly. Defaults to None.

Returns:
  • list

    List of channel indices to use for spot analysis.

Example

image_shape = (10, 256, 256, 5) # (z, h, w, c) ch_nuclei = 0 first_spot_channel = 1 second_spot_channel = None get_spot_channels(image_shape, ch_nuclei, first_spot_channel, second_spot_channel) [2, 3, 4]

second_spot_channel = 3 get_spot_channels(image_shape, ch_nuclei, first_spot_channel, second_spot_channel) [3]

second_spot_channel = [2, 4] get_spot_channels(image_shape, ch_nuclei, first_spot_channel, second_spot_channel) [2, 4]

get_sub_pixel_coordinates_through_gaussian_fit(coords, original_image, voxel_size=1, spot_radius=1)

Refine spot coordinates to sub-pixel accuracy using Gaussian fitting.

Parameters:
  • coords (array - like) –

    Coordinates of detected spots with shape (N_spots, N_dims).

  • original_image (ndarray) –

    Original 2D or 3D image in which spots were detected.

  • voxel_size (float or sequence, default: 1 ) –

    Voxel or pixel size in each dimension. Defaults to 1.

  • spot_radius (float or sequence, default: 1 ) –

    Approximate radius of the spots used for Gaussian fitting. Defaults to 1.

Returns:
  • np.ndarray: Array of sub-pixel refined coordinates for each spot.

Example
>>> coords = np.array([[10, 15], [20, 25]])
>>> image = np.random.random((50, 50))
>>> refined = get_sub_pixel_coordinates_through_gaussian_fit(coords, image)
>>> refined.shape
(2, 2)


merge_coords(*regions, remove_dupes=True)

Merge multiple sets of coordinates into a single set.

Parameters:
  • *regions (ndarray, default: () ) –

    Variable number of regions (sets of coordinates).

  • remove_dupes (bool, default: True ) –

    Whether to remove duplicate coordinates. Defaults to True.

Returns:
  • np.ndarray: The merged coordinates.

Example
>>> import numpy as np
>>> coords1 = np.array([[1, 2], [3, 4]])
>>> coords2 = np.array([[3, 4], [5, 6]])
>>> result = merge_coords(coords1, coords2)
>>> print(result)
[[1 2]
 [3 4]
 [5 6]]

negative_to_positive_index(arr_shape, index)

Converts a negative index to a positive index for a NumPy ndarray.

Parameters:
  • arr_shape (tuple) –

    Shape of the NumPy array (e.g., (z, h, w, c)).

  • index (int) –

    The index to convert (can be negative or positive).

Returns:
  • int

    The positive index.

Raises:
  • IndexError

    If the index is out of bounds for the given array shape.

Example

arr_shape = (10, 256, 256, 5) negative_to_positive_index(arr_shape, -1) 4 negative_to_positive_index(arr_shape, 2) 2

pair_spots(paths, PAIRING_THRESHOLD=250, first_spot_channel=1, second_spot_channels=-1)

Align and pair detected spots across channels for multiple datasets, both with and without restricting detection to nuclear regions.

For each dataset path, the pairing pipeline is executed twice: once considering all detected spots, and once considering only spots located inside nuclei.

Parameters:
  • paths (list[str]) –

    List of file paths or dataset identifiers to process.

  • PAIRING_THRESHOLD (float, default: 250 ) –

    Maximum distance (in µm or scaled units) allowed for pairing spots. Defaults to 250.

  • first_spot_channel (int, default: 1 ) –

    Channel index for the reference spot channel. Defaults to 1.

  • second_spot_channels (list[int] or None, default: -1 ) –

    List of channel indices for spot channels to pair with the first_spot_channel. If None, all channels except nuclei and first_spot_channel are used. Defaults to None.

Returns:
  • None

    Results are written to the corresponding databases.

Example
paths = ["sample_01.tif", "sample_02.tif"]
pair_spots(
    paths,
    PAIRING_THRESHOLD=200,
    first_spot_channel=1,
    second_spot_channels=[2, 3, 4]
)

plot_all_paired_spots(paths, ch1=1, ch2=2)

Render paired spot coordinates as 3D lines directly on the original image for all available tables that start with 'points_n_distances3D'.

Parameters:
  • paths (list[str]) –

    Paths to images from which the associated FISH databases are inferred.

Returns:
  • None

    This function generates and saves binary images with rendered

  • 3D lines for each table but does not return a value.

plot_analysis(paths, distance_cut_off=2.5, group_files_by_name_similarity=False, output_file_name=None, table_names=['points_n_distances3D_only_in_nuclei_acc', 'points_n_distances3D_only_in_nuclei_lcc'])

Generate violin plots of distances from FISH analysis datasets with optional grouping.

This function loads distance data from multiple FISH.db files, filters by a cutoff distance, optionally groups datasets by filename similarity, and generates violin plots with median annotations.

Parameters:
  • paths (list of str) –

    List of paths to FISH datasets or directories containing 'FISH.db'.

  • distance_cut_off (float, default: 2.5 ) –

    Maximum distance (µm) to include in the plot. Default is 2.5.

  • group_files_by_name_similarity (bool, default: False ) –

    If True, group datasets based on filename similarity. Default is False.

  • output_file_name (str or None, default: None ) –

    Path to save the PDF of the plot. If None, displays the plot. Default is None.

  • table_names (list of str, default: ['points_n_distances3D_only_in_nuclei_acc', 'points_n_distances3D_only_in_nuclei_lcc'] ) –

    List of database table names to extract distances from. Default is the two CHAB-corrected tables.

Returns:
  • None

    The plot is either displayed or saved to a file.

Example
paths = ['dataset1', 'dataset2']
plot_analysis(paths, distance_cut_off=3.0, group_files_by_name_similarity=True,
              output_file_name='violin_plot.pdf')

plot_distance_distribution(distances, outputfile_name)

Compute distribution statistics for a list/array of distances, print them, and save a histogram plot to a file.

Parameters:
  • distances (array - like) –

    Numeric distance values for which the distribution will be analyzed.

  • outputfile_name (str) –

    Path where the generated plot will be saved (e.g., "output.png").

Returns:
  • None

Example
distances = [1.2, 2.5, 3.0, 4.1, 2.9]
outputfile = 'distance_histogram.png'
plot_distance_distribution(distances, outputfile)

plot_histo(distances, median=None, q1_q3=None, title=None)

Plot a histogram of distance values and annotate it with the median and interquartile range.

Parameters:
  • distances (array - like) –

    List or NumPy array of numeric distance values.

  • median (float, default: None ) –

    Precomputed median to plot. If None, it is computed from distances. Defaults to None.

  • q1_q3 (tuple[float, float], default: None ) –

    Tuple containing the first and third quartiles (Q1, Q3). If None, they are computed from distances using get_q1_q3. Defaults to None.

  • title (str, default: None ) –

    Title to display above the histogram. Defaults to None.

Returns:
  • None

    This function produces a plot but does not return a value.

Example
distances = [1.2, 1.5, 1.7, 2.0, 2.1]
plot_histo(distances, title="Distance distribution")

plot_violin_with_median(data, **kwargs)

Create a violin plot for the 'distance' column of a DataFrame and annotate it with the median.

Parameters:
  • data (DataFrame) –

    DataFrame containing a 'distance' column to visualize.

  • **kwargs

    Additional keyword arguments passed to seaborn.violinplot (e.g., palette, color, scale).

Returns:
  • None

    The plot is drawn on the current Matplotlib axis.

Example
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

df = pd.DataFrame({'distance': [1.2, 2.5, 1.8, 3.0, 2.2]})
plot_violin_with_median(df, palette='muted')
plt.show()

run_analysis(paths, correction_matrix_save_path, PAIRING_THRESHOLD=60, ch_nuclei=0, first_spot_channel=1, second_spot_channel=-1, area_threshold=None, channels_to_blur=None, blur_mode='recursive2D', deep_learning='rapid', threshold_spot_ch1=0.5, threshold_nuclei=0.5, threshold_spot_ch2=0.5, RUN_SEG=True, RUN_REG=False, RUN_DISTANCE_MEASUREMENTS=True, RUN_CTRLS=True, RUN_GAUSSIAN_FIT=True, nuclear_model_to_use='nuclear_model_0', spot_model_to_use='spot_model_0', list_pairs_for_reg=None)

Execute a full pipeline for FISH spot and nuclei analysis including segmentation, spot detection, pairing, registration, distance measurements, controls, and plotting.

Parameters:
  • paths (list[str]) –

    List of dataset paths to analyze.

  • correction_matrix_save_path (str) –

    Path to save affine transformation / registration matrices.

  • PAIRING_THRESHOLD (float, default: 60 ) –

    Maximum distance for pairing spots (default 60).

  • ch_nuclei (int, default: 0 ) –

    Channel index for nuclei (default 0).

  • first_spot_channel (int, default: 1 ) –

    Channel index for first spot type (default 1).

  • second_spot_channel (int, default: -1 ) –

    Channel index for second spot type (default -1).

  • area_threshold (float or None, default: None ) –

    Minimum area threshold for detected nuclei.

  • channels_to_blur (list[int] or None, default: None ) –

    Channels to apply blur to during preprocessing.

  • blur_mode (str, default: 'recursive2D' ) –

    Blur mode for preprocessing ('recursive2D' by default).

  • deep_learning (str, default: 'rapid' ) –

    Model type for deep learning segmentation ('rapid' by default).

  • threshold_spot_ch1 (float, default: 0.5 ) –

    Threshold for first spot channel segmentation (default 0.5).

  • threshold_nuclei (float, default: 0.5 ) –

    Threshold for nuclei segmentation (default 0.5).

  • threshold_spot_ch2 (float, default: 0.5 ) –

    Threshold for second spot channel segmentation (default 0.5).

  • RUN_SEG (bool, default: True ) –

    If True, perform segmentation and spot detection (default True).

  • RUN_REG (bool, default: False ) –

    If True, perform registration (default False).

  • RUN_DISTANCE_MEASUREMENTS (bool, default: True ) –

    If True, compute distances and apply corrections (default True).

  • RUN_CTRLS (bool, default: True ) –

    If True, generate control images for visual inspection (default True).

  • list_pairs_for_reg (list, default: None ) –

    List of point pairs used for registration (default None).

Returns:
  • None

    Saves results, plots, and control images to disk.

Example
paths = ["dataset1.tif", "dataset2.tif"]
correction_matrix_save_path = "corrections/"
run_analysis(
    paths,
    correction_matrix_save_path,
    PAIRING_THRESHOLD=50,
    ch_nuclei=0,
    first_spot_channel=1,
    second_spot_channel=2,
    RUN_SEG=True,
    RUN_REG=True,
    RUN_DISTANCE_MEASUREMENTS=True,
    RUN_CTRLS=True
)

segment_spots_and_nuclei(paths, ch_nuclei=0, first_spot_channel=1, second_spot_channel=-1, __autoskip=True, channels_to_blur=None, blur_mode='recursive2D', deep_learning='rapid', nuclear_model_to_use='nuclear_model_0', spot_model_to_use='spot_model_0')

Segment nuclei and spot channels in microscopy images using deep-learning models.

Parameters:
  • paths (list[str]) –

    List of paths to input images. Each image is expected to be a 4D stack with dimensions (z, y, x, c).

  • ch_nuclei (int or None, default: 0 ) –

    Index of the nuclear channel. If None, nuclear segmentation is skipped. Defaults to 0.

  • first_spot_channel (int, default: 1 ) –

    Channel index for the first spot signal. Defaults to 1.

  • second_spot_channel (int, default: -1 ) –

    Channel index for the second spot signal. Defaults to -1 (last channel).

  • __autoskip (bool, default: True ) –

    Whether to skip segmentation if the output files already exist. Defaults to True.

  • channels_to_blur (list[int] or None, default: None ) –

    List of channel indices to blur before segmentation. Defaults to None.

  • blur_mode (str, default: 'recursive2D' ) –

    Blurring mode passed to blur_3D. Defaults to "recursive2D".

  • deep_learning (str, default: 'rapid' ) –

    Flag controlling prediction behavior. If it contains "rapid" or "fast", slow averaging augmentations are disabled. Defaults to "rapid".

Returns:
  • None

    Segmentation results are written to disk as TIFF files.

Example
paths = ["img1.tif", "img2.tif"]
segment_spots_and_nuclei(
    paths,
    ch_nuclei=0,
    first_spot_channel=1,
    second_spot_channel=2,
    channels_to_blur=[0, 1],
    blur_mode="recursive2D"
)

set_nb_channels(db_path, nb_channels)

Inserts the number of channels of an image into an SQLite database table named 'nb_channels' with a single column 'nb'.

Parameters:
  • db_path (str) –

    The path to the SQLite database file.

  • nb_channels (int) –

    The number of channels in the image.

Returns:
  • None.