TL;DR
cp_measure is a lightweight, API-first Python library that extracts the core feature-engineering engine of CellProfiler and strips away the cumbersome graphical interface and heavyweight dependencies. By providing a modular, programmatic interface for classical morphological profiling, it enables seamless integration with modern data science workflows—from scikit-learn models to massive spatial transcriptomics datasets in the scverse ecosystem.
What Problem Does This Paper Address?
Image-based morphological profiling extracts hundreds to thousands of quantitative visual metrics (e.g., cell shape, staining intensity, texture) from microscopy images to capture disease phenotypes and drug responses. For over a decade, CellProfiler has served as the gold standard for this task. However, CellProfiler was designed around an interactive, point-and-click GUI and relies on a complex stack of Python and Java dependencies.
This design creates severe bottlenecks for modern computational workflows:
- Automation & Scaling: CellProfiler cannot easily be scripted into lightweight, headless machine learning pipelines, nor does it scale gracefully to modern multi-gigabyte spatial biology images containing 500,000+ cells.
- Ecosystem Fragmentation: Alternative libraries (such as
scikit-imageorScaleFex) compute different feature spaces, making comparisons against reference repositories like the Cell Painting Gallery difficult or enforcing rigid file-directory structures. - The Interpretability Gap: While deep learning embeddings are popular, domain scientists still rely heavily on engineered features because of their direct mathematical and biological interpretability (e.g., protein co-localization, nuclear eccentricity) and low computational requirements.
Methods
The authors created cp_measure by extracting CellProfiler’s core measurement routines into a standalone Python library while discarding the graphical user interface, pipeline orchestrator, and non-essential dependencies:
- Modular Input Categorization: Measurements follow CellProfiler nomenclature and are organized strictly by input signature:
- Single Object: extracts morphology (e.g., area, eccentricity).
- Object + Single Channel: extracts intensity and texture features.
- Object + Multiple Channels: extracts spatial inter-channel statistics (e.g., Manders correlation coefficients).
- Streaming Spatial Integration: To handle extremely large spatial transcriptomics images, the authors integrated
cp_measureinto theSquidpypackage. Using theSpatialDataformat, images and spatial regions are processed in streaming parallel batches, completely bypassing the memory bottlenecks of traditional bioimage tools.
Datasets
The authors evaluated cp_measure across three distinct datasets:
- JUMP Cell Painting Dataset: 300 representative images covering 150 biological perturbations, used to benchmark numerical feature parity against standard CellProfiler.
- 3D Astrocyte Nuclei Dataset: 433 3D confocal images containing 831 astrocyte nuclei across multiple differentiation days.
- 10x Genomics Xenium Breast Cancer Dataset: Two large formalin-fixed paraffin-embedded (FFPE) spatial transcriptomics tissue sections (infiltrating ductal carcinoma and invasive lobular carcinoma) with paired H&E images tessellated into 18,469 hexagonal regions of interest.
Key Insights and Ideas
- Near-Perfect Fidelity Without the Baggage: Decoupling the feature extraction logic does not require reinventing the mathematical formulations.
cp_measurepreserves the exact feature semantics expected by downstream profiling tools likepycytominer. - Engineered Morphology Still Rivals Black Boxes: Hand-crafted features remain essential when mechanistic hypotheses are required; for example, SHAP analyses directly exposed nuclear widening as the hallmark of astrocyte maturation.
- Unsupervised Morphology Mirrors Molecular Profiles: Featurizing tissue tiles using standard morphological metrics alone enabled unsupervised Leiden clustering that closely aligned with transcriptomics-derived cell-type distributions (separating fibroblast-dense regions from adipocytes and identifying intra-tumor immune-hot signatures).
Key Results
- Feature Parity: Over 95% of extracted features achieved an $R^2 > 0.9$ compared directly against CellProfiler’s output on identical segmentation masks and images.
- Biological Classification: In the 3D astrocyte dataset, morphological features extracted by
cp_measuretrained a Gradient Boosting classifier that predicted the differentiation day with 87% test accuracy. SHAP analysis highlighted nuclear minor axis length as the most predictive metric. - Spatial Transcriptomics Throughput: Successfully featurized 18,469 hexagonal masks spanning two large breast cancer samples into 945 raw features (filtered down to 252 features post-QC), seamlessly integrating morphology with
Scanpy/Squidpysingle-cell analysis.
Limitations and Future Work
- Edge Cases: A small fraction (<5%) of features exhibited lower correlation ($R^2 \le 0.9$) due to subtle differences in how edge cases are handled between
cp_measureand CellProfiler. - Test Suite & Performance Bottlenecks: CellProfiler historically lacked an exhaustive mathematical test suite; developing one is necessary before aggressive refactoring. Furthermore, high-compute measurements (such as granularity) remain computationally heavy.
- Future Directions: The authors propose making
cp_measurean upstream dependency of CellProfiler itself, implementing just-in-time (JIT) compilation, adding native GPU support, and providing an open platform for community-contributed measurement plugins.
Summary updated