Interactive segmentation-based colocalization analysis for microscopy images
Project description
CellColoc: A Python package for interactive, segmentation-based colocalization analysis in microscopy images
CellColoc is a Python package for interactive, segmentation-based colocalization analysis in microscopy images.
It is designed for experiments where you want to:
- segment a larger biological object in one channel, such as soma, cytoplasm, neurites, or another cellular compartment,
- segment or threshold a second channel that defines marker positivity,
- classify cells as marker-positive or marker-negative based on overlap,
- optionally segment a third channel for ROI occupancy quantification and, if desired, third-channel cell positivity,
- inspect and refine results interactively in napari.
The package supports both 2D and 3D data, including optional ROI-based analysis, optional global z cropping, optional z projection, and fast post hoc Cellpose threshold refinement.
Core idea
CellColoc is built around a simple but flexible model:
- one primary
cellchannel, - one primary
markerchannel, - an optional third channel for additional occupancy quantification or optional third-marker positivity analysis.
Each analysis channel can use one of several segmentation backends:
cellposeotsulipercentile
This means CellColoc is not limited to Cellpose-only workflows. You can mix neural-network segmentation and classical intensity-threshold segmentation channel by channel within the same analysis script.
What CellColoc does
For each analysis run, the package can:
- load microscopy images through
omio-microscopy, - resolve voxel size either from user input or OMIO metadata,
- optionally prepare a global analysis view using z cropping and/or z projection,
- let the user draw 2D ROIs in napari or reuse existing ROI masks,
- segment each configured channel with Cellpose or threshold-based methods,
- measure overlap between segmented cells and marker objects,
- classify each cell as marker-positive or marker-negative,
- optionally quantify occupancy metrics for every segmented channel,
- optionally classify cells as positive for the third channel as well,
- export masks and result tables to a standardized
results/folder, - allow interactive post hoc refinement and manual relabel-based reanalysis.
Main features
- Interactive user-script workflow for VS Code interactive window or notebook-like execution
- Reusable core package separated from project-specific scripts
- 2D and 3D image handling
- Automatic dimensionality detection from OMIO-loaded
TZCYXdata - Optional ROI drawing in napari
- Optional whole-image analysis as one ROI
- Optional reuse of previously saved ROI masks
- Channel-wise segmentation method selection
- Optional prefilter chains such as
["median", "gaussian"] - Optional mask postfilters such as
min_intensity,local_contrast, andbright_pixel_support - Optional anisotropy handling for true 3D Cellpose runs
- Optional 3D flow smoothing for Cellpose
- Optional global z crop for internal analysis
- Optional global z projection using
max,mean,median,std, orvar - Fast Cellpose cache-based threshold refinement without rerunning the network forward pass
- Optional manual mask editing in napari followed by table recomputation
- Standardized export of masks, CSV tables, and Excel workbooks
Repository layout
cellcoloc/Reusable package containing image loading, ROI handling, segmentation, colocalization logic, filtering, visualization, export, and runtime helpers.user_scripts/Interactive project-specific scripts that configure real datasets and call the package step by step.example_data/Example datasets and example results.
Analysis workflow
The recommended workflow is to run a user script cell by cell.
Typical steps are:
- define paths, channels, and display names,
- set segmentation methods and model parameters,
- optionally define z cropping or z projection,
- load and prepare the analysis channels,
- draw or reload ROIs,
- run segmentation and colocalization,
- inspect the masks and tables in napari,
- optionally refine thresholds or edit masks,
- export final results.
This structure keeps project settings in the user scripts while the reusable analysis logic stays inside the package.
Segmentation backends
CellColoc currently supports the following segmentation approaches for analysis channels:
cellposeUseful for object-centric segmentation of cells, somata, nuclei, or similar structures.otsuGlobal Otsu thresholding followed by morphology cleanup and connected-component labeling.liLi thresholding followed by morphology cleanup and connected-component labeling.percentileFixed percentile thresholding followed by morphology cleanup and connected-component labeling.
These methods can be chosen independently for each channel.
ROIs and 3D behavior
ROIs are drawn as 2D polygons in napari. They are then reused for all downstream computations.
By default:
- a 2D ROI is applied across the analysis stack in
z, - segmentation is run only inside the ROI crop bounding box,
- everything outside the ROI mask is zeroed before segmentation.
In addition, CellColoc now supports:
- global analysis z cropping via
z_crop=(start, stop), - global z projection via
z_projection="max"or related methods.
If a z projection is enabled, all later analysis and visualization steps operate on the projected 2D analysis view.
Marker positivity logic
Cells are segmented from the configured cell channel. Marker objects are segmented independently from the configured marker channel.
A cell is counted as marker-positive only if:
- it overlaps at least one marker object,
- the best overlap reaches
min_overlap_voxels, - the best overlap fraction reaches
overlap_fraction_threshold.
This rule is explicit and configurable through ColocalizationConfig.
Optional third-channel analysis
An optional third channel can be included for additional analysis.
Supported use cases include:
- occupancy-only analysis, for example lesion, tumor, or infiltration coverage,
- separate third-channel cell positivity,
- derived double-positive counts for cells that are positive for both the main marker and the third segmented channel.
For each segmented channel, CellColoc can report:
- projected 2D occupied area,
- 2D occupancy percentage,
- 3D occupied volume,
- 3D occupancy percentage.
Outputs
All outputs are written to a results/ subfolder next to the raw dataset.
Typical mask outputs include:
- ROI label mask
- cell mask
- marker mask
- marker-positive cell mask
- optional third-channel mask
Tabular outputs include:
detailedone row per cell-marker overlap eventsummaryone row per cell with positivity and overlap summaryoverviewone row per ROI with counts, geometry, and occupancy metrics
The detailed table is exported as CSV. All tables are also exported together into an Excel workbook.
Installation
Either way you choose, first create and activate a Python 3.12 environment, for example:
conda create -n cellcoloc python=3.12 -y
conda activate cellcoloc
From PyPI
pip install cellcoloc
For notebook or VS Code interactive use, the optional interactive extra can be installed with:
pip install "cellcoloc[interactive]"
From source
git clone https://github.com/FabrizioMusacchio/CellColoc.git
cd CellColoc
pip install -e .
For interactive use from source:
pip install -e ".[interactive]"
Upgrading CellColoc
To upgrade an existing CellColoc installation to the latest version, you can use pip's upgrade flag:
pip install --upgrade cellcoloc
or, if you installed with the interactive extra:
pip install --upgrade "cellcoloc[interactive]"
For source installations, you can pull the latest changes and reinstall:
cd CellColoc
git pull origin main
pip install -e .
or
pip install -e ".[interactive]"
Cellpose 3 and Cellpose 4
CellColoc is designed to work with both older Cellpose 3 installations and newer Cellpose 4 installations.
Default install:
pip install cellcoloc
If you specifically want the tested Cellpose 3 variant:
pip install "cellcoloc[cellpose3]"
Alternatively, users can also install CellColoc first and then pin Cellpose manually:
pip install cellcoloc
pip install "cellpose==3.1.1.2"
Current requirements
The package is currently prepared for Python 3.12.
Core dependencies include:
cellposeomio-microscopymatplotlibpandasopenpyxlscikit-imageappdirs
The optional interactive extra adds:
ipykernel
Citation
If you use CellColoc in your work, please cite the package using the information in CITATION.cff.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cellcoloc-0.0.2.tar.gz.
File metadata
- Download URL: cellcoloc-0.0.2.tar.gz
- Upload date:
- Size: 244.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.34.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ceeb950e2899829061eb49bac3bb85ae1c3a034322713e55bd4002d746da674e
|
|
| MD5 |
44c81c6d2b70301c1f36ad37c4ba7816
|
|
| BLAKE2b-256 |
236c1a002c1d47d71f6fa4774c0b29f80588c52aabfe130530804a12c821982c
|
File details
Details for the file cellcoloc-0.0.2-py3-none-any.whl.
File metadata
- Download URL: cellcoloc-0.0.2-py3-none-any.whl
- Upload date:
- Size: 54.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.34.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
de55586cf67c2ee5a383ad88226afba3b4e453b7035558151b83d850be38970f
|
|
| MD5 |
6f20946e074aa5b7e0110faf4be1fbdb
|
|
| BLAKE2b-256 |
1aaf92008b7eb5c0af9a8e816a64215f3ff3e9f78a8a14d1050a885e777f4ee0
|