samcell


Namesamcell JSON
Version 1.2.0 PyPI version JSON
download
home_pagehttps://github.com/saahilsanganeriya/SAMCell
SummaryGeneralized label-free biological cell segmentation with Segment Anything
upload_time2025-10-09 23:46:35
maintainerNone
docs_urlNone
authorNathan J. Malta, Emilio Aponte, Caitlin van Zyl, Danfei Xu, Craig Forest
requires_python>=3.8
licenseMIT License Copyright (c) 2025 Saahil Sanganeriya Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords cell segmentation microscopy computer vision deep learning segment anything biology image analysis
VCS
bugtrack_url
requirements torch transformers numpy opencv-python-headless scikit-image scipy pandas tqdm Pillow safetensors openpyxl
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # SAMCell: Generalized Label-Free Biological Cell Segmentation

[![Python 3.8+](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Paper](https://img.shields.io/badge/Paper-PLOS%20ONE-red.svg)](https://doi.org/10.1371/journal.pone.0319532)

SAMCell is a state-of-the-art deep learning model for automated cell segmentation in microscopy images. Built on Meta's Segment Anything Model (SAM), SAMCell uses a novel distance map regression approach with watershed post-processing to achieve superior performance for label-free cell segmentation across diverse cell types and imaging conditions.

## 🌟 Key Features

- **State-of-the-art Performance**: Outperforms existing methods like Cellpose, Stardist, and CALT-US on both test-set and zero-shot cross-dataset evaluation
- **Zero-shot Generalization**: Works on novel cell types and microscopes not seen during training
- **Distance Map Regression**: Predicts Euclidean distance to cell boundaries instead of binary masks, enabling better separation of densely packed cells
- **Vision Transformer Architecture**: Leverages SAM's ViT-based encoder pretrained on 11M images for robust feature extraction
- **Comprehensive Metrics**: Calculate 30+ morphological and intensity-based cell metrics
- **Easy Integration**: Simple Python API with minimal setup
- **Multiple Interfaces**: Command-line tool, Python API, GUI, and Napari plugin

## 📊 Performance

SAMCell demonstrates superior performance in both test-set and zero-shot cross-dataset evaluation:

### Test-Set Performance

| Dataset | Method | SEG | DET | OP_CSB |
|---------|--------|-----|-----|--------|
| LIVECell | **SAMCell** | **0.652** | **0.893** | **0.772** |
| | Cellpose | 0.589 | 0.779 | 0.684 |
| | Stardist | 0.572 | 0.771 | 0.671 |
| Cytoplasm | **SAMCell** | **0.611** | **0.866** | **0.739** |
| | Cellpose | 0.580 | 0.749 | 0.664 |
| | Stardist | 0.557 | 0.774 | 0.666 |

### Zero-Shot Cross-Dataset Performance

| Dataset | Method | SEG | DET | OP_CSB |
|---------|--------|-----|-----|--------|
| PBL-HEK | **SAMCell-Generalist** | **0.425** | **0.772** | **0.598** |
| | Cellpose-Cyto | 0.253 | 0.388 | 0.320 |
| | Stardist-Cyto | 0.142 | 0.236 | 0.189 |
| PBL-N2a | **SAMCell-Generalist** | **0.707** | **0.941** | **0.824** |
| | Cellpose-Cyto | 0.642 | 0.885 | 0.764 |
| | Stardist-Cyto | 0.597 | 0.851 | 0.724 |

*SAMCell-Generalist trained on LIVECell + Cytoplasm datasets. PBL-HEK and PBL-N2a contain novel cell types not seen during training.*

## 🚀 Quick Start

### Installation

```bash
# Install from PyPI (recommended)
pip install samcell

# Or install from source
git clone https://github.com/saahilsanganeriya/SAMCell.git
cd SAMCell
pip install -e .
```

### Download Pre-trained Weights

Download the pre-trained SAMCell model weights:

```bash
# SAMCell-Generalist (recommended)
wget https://github.com/saahilsanganeriya/SAMCell/releases/download/v1/samcell-generalist.pt

# Or SAMCell-Cyto
wget https://github.com/saahilsanganeriya/SAMCell/releases/download/v1/samcell-cyto.pt
```

### Basic Usage

```python
import cv2
import samcell

# Load your microscopy image
image = cv2.imread('your_image.png', cv2.IMREAD_GRAYSCALE)

# Initialize SAMCell
model = samcell.FinetunedSAM('facebook/sam-vit-base')
model.load_weights('samcell-generalist.pt')

# Create pipeline
pipeline = samcell.SAMCellPipeline(model, device='cuda')

# Segment cells
labels = pipeline.run(image)

# Calculate metrics
metrics_df = pipeline.calculate_metrics(labels, image)
print(f"Found {len(metrics_df)} cells")

# Export results
pipeline.export_metrics(labels, 'cell_metrics.csv', image)
```

### Command Line Interface

```bash
# Basic segmentation
samcell segment image.png --model samcell-generalist.pt --output results/

# With comprehensive metrics
samcell segment image.png --model samcell-generalist.pt --output results/ --export-metrics

# Custom thresholds
samcell segment image.png --model samcell-generalist.pt --peak-threshold 0.5 --fill-threshold 0.1
```

## 📋 Requirements

- Python ≥ 3.8
- PyTorch ≥ 1.9.0
- transformers ≥ 4.26.0
- OpenCV ≥ 4.5.0
- scikit-image ≥ 0.19.0
- pandas ≥ 1.3.0

For GPU acceleration:
- CUDA-compatible GPU
- CUDA Toolkit ≥ 11.0

## 🔧 Advanced Usage

### Custom Thresholds

SAMCell uses two key thresholds for post-processing:

```python
# Default values (optimized across datasets)
pipeline = samcell.SAMCellPipeline(model, device='cuda')
labels = pipeline.run(image, cells_max=0.47, cell_fill=0.09)
```

### Batch Processing

```python
# Process multiple images
images = [cv2.imread(f'image_{i}.png', 0) for i in range(10)]

results = []
for image in images:
    labels = pipeline.run(image)
    metrics = pipeline.calculate_metrics(labels, image)
    results.append(metrics)

# Combine all metrics
import pandas as pd
all_metrics = pd.concat(results, ignore_index=True)
```

### Comprehensive Metrics

SAMCell calculates 30+ morphological and intensity metrics:

```python
# Basic metrics (fast)
basic_metrics = samcell.calculate_basic_metrics(labels, image)

# Include neighbor analysis
neighbor_metrics = samcell.calculate_neighbor_metrics(labels)

# Full analysis including texture (slower)
full_metrics = samcell.calculate_all_metrics(
    labels, image, include_texture=True
)
```

## 🖥️ GUI and Napari Plugin

### Standalone GUI

```bash
# Install GUI dependencies
pip install samcell[gui]

# Launch GUI
python -m samcell.gui
```

### Napari Plugin

```bash
# Install napari plugin
pip install samcell[napari]

# Launch napari and find SAMCell in the plugins menu
napari
```

## 📖 Documentation

### API Reference

#### `FinetunedSAM`

```python
model = samcell.FinetunedSAM(sam_model='facebook/sam-vit-base')
model.load_weights(weight_path, map_location='cuda')
```

#### `SAMCellPipeline`

```python
pipeline = samcell.SAMCellPipeline(
    model,                    # FinetunedSAM instance
    device='cuda',           # 'cuda' or 'cpu'
    crop_size=256,          # Patch size for sliding window
)

# Run segmentation
labels = pipeline.run(
    image,                   # Input grayscale image
    cells_max=0.47,         # Cell peak threshold
    cell_fill=0.09,         # Cell fill threshold
    return_dist_map=False   # Return distance map
)
```

#### Metrics Functions

```python
# Calculate all metrics
metrics_df = samcell.calculate_all_metrics(
    labels,                  # Segmentation labels
    original_image=None,     # Original image for intensity metrics
    include_texture=False,   # Include texture analysis
    neighbor_distance=10     # Distance for neighbor analysis
)

# Export to CSV
success = samcell.export_metrics_csv(
    labels,
    'output.csv',
    original_image=image,
    include_texture=False
)
```

### Available Metrics

SAMCell calculates comprehensive morphological metrics:

**Shape Metrics:**
- Area, Perimeter, Convex Area
- Compactness, Circularity, Roundness
- Aspect Ratio, Eccentricity, Solidity
- Major/Minor Axis Lengths

**Spatial Metrics:**
- Centroid coordinates
- Bounding box dimensions
- Number of neighbors
- Nearest neighbor distances

**Intensity Metrics** (when original image provided):
- Mean, Standard deviation, Min/Max intensity
- Intensity range and distribution

**Texture Metrics** (optional):
- GLCM-based features
- Contrast, Homogeneity, Energy
- Correlation, Dissimilarity

## 🔬 Method Overview

SAMCell introduces several key innovations for robust cell segmentation:

### 1. Distance Map Regression
Instead of predicting binary masks or multi-class segmentation, SAMCell predicts a continuous-valued distance map where each pixel value represents the normalized Euclidean distance from that pixel to its cell's boundary (0 to 1 range). This approach effectively addresses the challenge of segmenting densely packed cells with ambiguous boundaries.

### 2. Vision Transformer Architecture
SAMCell inherits SAM's ViT-based image encoder pretrained on 11 million diverse natural images. This extensive pretraining provides:
- Strong priors for boundary detection across imaging conditions
- Long-range dependency modeling via self-attention mechanisms
- Superior generalization to novel cell types and microscopes

### 3. Watershed Post-Processing
Converts predicted distance maps to discrete cell masks using the watershed algorithm:
- **Cell Peak Threshold (default: 0.47)**: Identifies cell centers from distance map peaks
- **Cell Fill Threshold (default: 0.09)**: Determines cell boundaries
- The watershed algorithm treats the distance map as a topographical surface, flooding from cell centers to naturally separate touching cells

### 4. Sliding Window Inference
Processes large microscopy images efficiently:
- Divides images into overlapping 256×256 patches (32-pixel overlap)
- Each patch upsampled to 1024×1024 for SAM's encoder
- Predictions stitched with cosine blending to avoid edge artifacts

### 5. No Prompting Required
Unlike vanilla SAM, SAMCell eliminates manual prompting by:
- Freezing the prompt encoder during fine-tuning
- Using SAM's default prompt embedding as a static input
- The mask decoder learns to predict distance maps from image embeddings alone

### Training Details
- **Model**: SAM-Base (ViT-B) with 89M parameters
- **Fine-tuning**: Full fine-tuning of image encoder and mask decoder
- **Loss**: Mean Squared Error (MSE) on sigmoid-activated predictions
- **Optimizer**: AdamW (lr=1e-4, weight decay=0.1)
- **Training**: Early stopping with patience=7, trained for 35 epochs on NVIDIA A100
- **Data Augmentation**: Random flip, rotation (-180° to 180°), scale (0.8-1.2×), brightness (0.95-1.05×), inversion
- **Preprocessing**: CLAHE (clipLimit=3.0, tileGridSize=8×8) for contrast enhancement

## 📊 Datasets

### Training Datasets
- **LIVECell**: 5,000+ phase-contrast images across 8 cell types containing ~1.7M individually annotated cells. All images captured with same microscope at standardized size (704×520 pixels). Provides large-scale training data with diverse cell morphologies and confluencies.
- **Cellpose Cytoplasm**: ~600 microscopy images from diverse internet sources. Includes both bright-field and fluorescent microscopy from different microscopes. Smaller but more diverse in imaging conditions. Images resized to 512×512 pixels preserving aspect ratio.

### Evaluation Datasets (Zero-Shot)
- **PBL-HEK**: 5 phase-contrast images of Human Embryonic Kidney 293 cells (~300 cells per image). Captured with different microscope than training data. Features densely packed cells with irregular morphologies.
- **PBL-N2a**: 5 phase-contrast images of Neuro-2a cells (~300 cells per image). Novel cell line and microscope not seen in training. More circular morphology with distinct boundaries compared to HEK cells.

Both evaluation datasets available at: https://github.com/saahilsanganeriya/SAMCell/releases/tag/v1

## 🤝 Contributing

We welcome contributions! Please see our [Contributing Guidelines](CONTRIBUTING.md) for details.

## 📄 Citation

If you use SAMCell in your research, please cite our paper:

VandeLoo AD*, Malta NJ*, Sanganeriya S, Aponte E, van Zyl C, et al. (2025) SAMCell: Generalized label-free biological cell segmentation with segment anything. PLOS ONE 20(9): e0319532. https://doi.org/10.1371/journal.pone.0319532

```bibtex
@article{vandeloo2025samcell,
    title={SAMCell: Generalized label-free biological cell segmentation with segment anything},
    author={VandeLoo, Alexandra Dunnum and Malta, Nathan J and Sanganeriya, Saahil and Aponte, Emilio and van Zyl, Caitlin and Xu, Danfei and Forest, Craig},
    journal={PLOS ONE},
    volume={20},
    number={9},
    pages={e0319532},
    year={2025},
    publisher={Public Library of Science},
    doi={10.1371/journal.pone.0319532},
    url={https://doi.org/10.1371/journal.pone.0319532}
}
```

## 📞 Support

- **Issues**: [GitHub Issues](https://github.com/saahilsanganeriya/SAMCell/issues)
- **Discussions**: [GitHub Discussions](https://github.com/saahilsanganeriya/SAMCell/discussions)
- **Email**: saahilsanganeriya@gatech.edu

## 📜 License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## 🏛️ Institutions

This work was developed at:
- **Georgia Institute of Technology**
  - School of Biological Sciences
  - School of Computer Science  
  - Department of Biomedical Engineering
  - School of Mechanical Engineering
  - School of Interactive Computing

## 🙏 Acknowledgments

- Meta AI for the original Segment Anything Model
- The open-source community for tools and datasets
- Georgia Tech for computational resources
- All contributors and users of SAMCell

---

**SAMCell Team** - Making cell segmentation accessible to everyone! 🔬✨

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/saahilsanganeriya/SAMCell",
    "name": "samcell",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "Saahil Sanganeriya <saahilsanganeriya@gatech.edu>",
    "keywords": "cell segmentation, microscopy, computer vision, deep learning, segment anything, biology, image analysis",
    "author": "Nathan J. Malta, Emilio Aponte, Caitlin van Zyl, Danfei Xu, Craig Forest",
    "author_email": "Alexandra Dunnum VandeLoo <adunnum1@gatech.edu>, Saahil Sanganeriya <saahilsanganeriya@gatech.edu>",
    "download_url": "https://files.pythonhosted.org/packages/82/f8/f6e86090773e226c4ad74534ca9c131b098e0eb0d42ec217634b4d22008f/samcell-1.2.0.tar.gz",
    "platform": null,
    "description": "# SAMCell: Generalized Label-Free Biological Cell Segmentation\n\n[![Python 3.8+](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![Paper](https://img.shields.io/badge/Paper-PLOS%20ONE-red.svg)](https://doi.org/10.1371/journal.pone.0319532)\n\nSAMCell is a state-of-the-art deep learning model for automated cell segmentation in microscopy images. Built on Meta's Segment Anything Model (SAM), SAMCell uses a novel distance map regression approach with watershed post-processing to achieve superior performance for label-free cell segmentation across diverse cell types and imaging conditions.\n\n## \ud83c\udf1f Key Features\n\n- **State-of-the-art Performance**: Outperforms existing methods like Cellpose, Stardist, and CALT-US on both test-set and zero-shot cross-dataset evaluation\n- **Zero-shot Generalization**: Works on novel cell types and microscopes not seen during training\n- **Distance Map Regression**: Predicts Euclidean distance to cell boundaries instead of binary masks, enabling better separation of densely packed cells\n- **Vision Transformer Architecture**: Leverages SAM's ViT-based encoder pretrained on 11M images for robust feature extraction\n- **Comprehensive Metrics**: Calculate 30+ morphological and intensity-based cell metrics\n- **Easy Integration**: Simple Python API with minimal setup\n- **Multiple Interfaces**: Command-line tool, Python API, GUI, and Napari plugin\n\n## \ud83d\udcca Performance\n\nSAMCell demonstrates superior performance in both test-set and zero-shot cross-dataset evaluation:\n\n### Test-Set Performance\n\n| Dataset | Method | SEG | DET | OP_CSB |\n|---------|--------|-----|-----|--------|\n| LIVECell | **SAMCell** | **0.652** | **0.893** | **0.772** |\n| | Cellpose | 0.589 | 0.779 | 0.684 |\n| | Stardist | 0.572 | 0.771 | 0.671 |\n| Cytoplasm | **SAMCell** | **0.611** | **0.866** | **0.739** |\n| | Cellpose | 0.580 | 0.749 | 0.664 |\n| | Stardist | 0.557 | 0.774 | 0.666 |\n\n### Zero-Shot Cross-Dataset Performance\n\n| Dataset | Method | SEG | DET | OP_CSB |\n|---------|--------|-----|-----|--------|\n| PBL-HEK | **SAMCell-Generalist** | **0.425** | **0.772** | **0.598** |\n| | Cellpose-Cyto | 0.253 | 0.388 | 0.320 |\n| | Stardist-Cyto | 0.142 | 0.236 | 0.189 |\n| PBL-N2a | **SAMCell-Generalist** | **0.707** | **0.941** | **0.824** |\n| | Cellpose-Cyto | 0.642 | 0.885 | 0.764 |\n| | Stardist-Cyto | 0.597 | 0.851 | 0.724 |\n\n*SAMCell-Generalist trained on LIVECell + Cytoplasm datasets. PBL-HEK and PBL-N2a contain novel cell types not seen during training.*\n\n## \ud83d\ude80 Quick Start\n\n### Installation\n\n```bash\n# Install from PyPI (recommended)\npip install samcell\n\n# Or install from source\ngit clone https://github.com/saahilsanganeriya/SAMCell.git\ncd SAMCell\npip install -e .\n```\n\n### Download Pre-trained Weights\n\nDownload the pre-trained SAMCell model weights:\n\n```bash\n# SAMCell-Generalist (recommended)\nwget https://github.com/saahilsanganeriya/SAMCell/releases/download/v1/samcell-generalist.pt\n\n# Or SAMCell-Cyto\nwget https://github.com/saahilsanganeriya/SAMCell/releases/download/v1/samcell-cyto.pt\n```\n\n### Basic Usage\n\n```python\nimport cv2\nimport samcell\n\n# Load your microscopy image\nimage = cv2.imread('your_image.png', cv2.IMREAD_GRAYSCALE)\n\n# Initialize SAMCell\nmodel = samcell.FinetunedSAM('facebook/sam-vit-base')\nmodel.load_weights('samcell-generalist.pt')\n\n# Create pipeline\npipeline = samcell.SAMCellPipeline(model, device='cuda')\n\n# Segment cells\nlabels = pipeline.run(image)\n\n# Calculate metrics\nmetrics_df = pipeline.calculate_metrics(labels, image)\nprint(f\"Found {len(metrics_df)} cells\")\n\n# Export results\npipeline.export_metrics(labels, 'cell_metrics.csv', image)\n```\n\n### Command Line Interface\n\n```bash\n# Basic segmentation\nsamcell segment image.png --model samcell-generalist.pt --output results/\n\n# With comprehensive metrics\nsamcell segment image.png --model samcell-generalist.pt --output results/ --export-metrics\n\n# Custom thresholds\nsamcell segment image.png --model samcell-generalist.pt --peak-threshold 0.5 --fill-threshold 0.1\n```\n\n## \ud83d\udccb Requirements\n\n- Python \u2265 3.8\n- PyTorch \u2265 1.9.0\n- transformers \u2265 4.26.0\n- OpenCV \u2265 4.5.0\n- scikit-image \u2265 0.19.0\n- pandas \u2265 1.3.0\n\nFor GPU acceleration:\n- CUDA-compatible GPU\n- CUDA Toolkit \u2265 11.0\n\n## \ud83d\udd27 Advanced Usage\n\n### Custom Thresholds\n\nSAMCell uses two key thresholds for post-processing:\n\n```python\n# Default values (optimized across datasets)\npipeline = samcell.SAMCellPipeline(model, device='cuda')\nlabels = pipeline.run(image, cells_max=0.47, cell_fill=0.09)\n```\n\n### Batch Processing\n\n```python\n# Process multiple images\nimages = [cv2.imread(f'image_{i}.png', 0) for i in range(10)]\n\nresults = []\nfor image in images:\n    labels = pipeline.run(image)\n    metrics = pipeline.calculate_metrics(labels, image)\n    results.append(metrics)\n\n# Combine all metrics\nimport pandas as pd\nall_metrics = pd.concat(results, ignore_index=True)\n```\n\n### Comprehensive Metrics\n\nSAMCell calculates 30+ morphological and intensity metrics:\n\n```python\n# Basic metrics (fast)\nbasic_metrics = samcell.calculate_basic_metrics(labels, image)\n\n# Include neighbor analysis\nneighbor_metrics = samcell.calculate_neighbor_metrics(labels)\n\n# Full analysis including texture (slower)\nfull_metrics = samcell.calculate_all_metrics(\n    labels, image, include_texture=True\n)\n```\n\n## \ud83d\udda5\ufe0f GUI and Napari Plugin\n\n### Standalone GUI\n\n```bash\n# Install GUI dependencies\npip install samcell[gui]\n\n# Launch GUI\npython -m samcell.gui\n```\n\n### Napari Plugin\n\n```bash\n# Install napari plugin\npip install samcell[napari]\n\n# Launch napari and find SAMCell in the plugins menu\nnapari\n```\n\n## \ud83d\udcd6 Documentation\n\n### API Reference\n\n#### `FinetunedSAM`\n\n```python\nmodel = samcell.FinetunedSAM(sam_model='facebook/sam-vit-base')\nmodel.load_weights(weight_path, map_location='cuda')\n```\n\n#### `SAMCellPipeline`\n\n```python\npipeline = samcell.SAMCellPipeline(\n    model,                    # FinetunedSAM instance\n    device='cuda',           # 'cuda' or 'cpu'\n    crop_size=256,          # Patch size for sliding window\n)\n\n# Run segmentation\nlabels = pipeline.run(\n    image,                   # Input grayscale image\n    cells_max=0.47,         # Cell peak threshold\n    cell_fill=0.09,         # Cell fill threshold\n    return_dist_map=False   # Return distance map\n)\n```\n\n#### Metrics Functions\n\n```python\n# Calculate all metrics\nmetrics_df = samcell.calculate_all_metrics(\n    labels,                  # Segmentation labels\n    original_image=None,     # Original image for intensity metrics\n    include_texture=False,   # Include texture analysis\n    neighbor_distance=10     # Distance for neighbor analysis\n)\n\n# Export to CSV\nsuccess = samcell.export_metrics_csv(\n    labels,\n    'output.csv',\n    original_image=image,\n    include_texture=False\n)\n```\n\n### Available Metrics\n\nSAMCell calculates comprehensive morphological metrics:\n\n**Shape Metrics:**\n- Area, Perimeter, Convex Area\n- Compactness, Circularity, Roundness\n- Aspect Ratio, Eccentricity, Solidity\n- Major/Minor Axis Lengths\n\n**Spatial Metrics:**\n- Centroid coordinates\n- Bounding box dimensions\n- Number of neighbors\n- Nearest neighbor distances\n\n**Intensity Metrics** (when original image provided):\n- Mean, Standard deviation, Min/Max intensity\n- Intensity range and distribution\n\n**Texture Metrics** (optional):\n- GLCM-based features\n- Contrast, Homogeneity, Energy\n- Correlation, Dissimilarity\n\n## \ud83d\udd2c Method Overview\n\nSAMCell introduces several key innovations for robust cell segmentation:\n\n### 1. Distance Map Regression\nInstead of predicting binary masks or multi-class segmentation, SAMCell predicts a continuous-valued distance map where each pixel value represents the normalized Euclidean distance from that pixel to its cell's boundary (0 to 1 range). This approach effectively addresses the challenge of segmenting densely packed cells with ambiguous boundaries.\n\n### 2. Vision Transformer Architecture\nSAMCell inherits SAM's ViT-based image encoder pretrained on 11 million diverse natural images. This extensive pretraining provides:\n- Strong priors for boundary detection across imaging conditions\n- Long-range dependency modeling via self-attention mechanisms\n- Superior generalization to novel cell types and microscopes\n\n### 3. Watershed Post-Processing\nConverts predicted distance maps to discrete cell masks using the watershed algorithm:\n- **Cell Peak Threshold (default: 0.47)**: Identifies cell centers from distance map peaks\n- **Cell Fill Threshold (default: 0.09)**: Determines cell boundaries\n- The watershed algorithm treats the distance map as a topographical surface, flooding from cell centers to naturally separate touching cells\n\n### 4. Sliding Window Inference\nProcesses large microscopy images efficiently:\n- Divides images into overlapping 256\u00d7256 patches (32-pixel overlap)\n- Each patch upsampled to 1024\u00d71024 for SAM's encoder\n- Predictions stitched with cosine blending to avoid edge artifacts\n\n### 5. No Prompting Required\nUnlike vanilla SAM, SAMCell eliminates manual prompting by:\n- Freezing the prompt encoder during fine-tuning\n- Using SAM's default prompt embedding as a static input\n- The mask decoder learns to predict distance maps from image embeddings alone\n\n### Training Details\n- **Model**: SAM-Base (ViT-B) with 89M parameters\n- **Fine-tuning**: Full fine-tuning of image encoder and mask decoder\n- **Loss**: Mean Squared Error (MSE) on sigmoid-activated predictions\n- **Optimizer**: AdamW (lr=1e-4, weight decay=0.1)\n- **Training**: Early stopping with patience=7, trained for 35 epochs on NVIDIA A100\n- **Data Augmentation**: Random flip, rotation (-180\u00b0 to 180\u00b0), scale (0.8-1.2\u00d7), brightness (0.95-1.05\u00d7), inversion\n- **Preprocessing**: CLAHE (clipLimit=3.0, tileGridSize=8\u00d78) for contrast enhancement\n\n## \ud83d\udcca Datasets\n\n### Training Datasets\n- **LIVECell**: 5,000+ phase-contrast images across 8 cell types containing ~1.7M individually annotated cells. All images captured with same microscope at standardized size (704\u00d7520 pixels). Provides large-scale training data with diverse cell morphologies and confluencies.\n- **Cellpose Cytoplasm**: ~600 microscopy images from diverse internet sources. Includes both bright-field and fluorescent microscopy from different microscopes. Smaller but more diverse in imaging conditions. Images resized to 512\u00d7512 pixels preserving aspect ratio.\n\n### Evaluation Datasets (Zero-Shot)\n- **PBL-HEK**: 5 phase-contrast images of Human Embryonic Kidney 293 cells (~300 cells per image). Captured with different microscope than training data. Features densely packed cells with irregular morphologies.\n- **PBL-N2a**: 5 phase-contrast images of Neuro-2a cells (~300 cells per image). Novel cell line and microscope not seen in training. More circular morphology with distinct boundaries compared to HEK cells.\n\nBoth evaluation datasets available at: https://github.com/saahilsanganeriya/SAMCell/releases/tag/v1\n\n## \ud83e\udd1d Contributing\n\nWe welcome contributions! Please see our [Contributing Guidelines](CONTRIBUTING.md) for details.\n\n## \ud83d\udcc4 Citation\n\nIf you use SAMCell in your research, please cite our paper:\n\nVandeLoo AD*, Malta NJ*, Sanganeriya S, Aponte E, van Zyl C, et al. (2025) SAMCell: Generalized label-free biological cell segmentation with segment anything. PLOS ONE 20(9): e0319532. https://doi.org/10.1371/journal.pone.0319532\n\n```bibtex\n@article{vandeloo2025samcell,\n    title={SAMCell: Generalized label-free biological cell segmentation with segment anything},\n    author={VandeLoo, Alexandra Dunnum and Malta, Nathan J and Sanganeriya, Saahil and Aponte, Emilio and van Zyl, Caitlin and Xu, Danfei and Forest, Craig},\n    journal={PLOS ONE},\n    volume={20},\n    number={9},\n    pages={e0319532},\n    year={2025},\n    publisher={Public Library of Science},\n    doi={10.1371/journal.pone.0319532},\n    url={https://doi.org/10.1371/journal.pone.0319532}\n}\n```\n\n## \ud83d\udcde Support\n\n- **Issues**: [GitHub Issues](https://github.com/saahilsanganeriya/SAMCell/issues)\n- **Discussions**: [GitHub Discussions](https://github.com/saahilsanganeriya/SAMCell/discussions)\n- **Email**: saahilsanganeriya@gatech.edu\n\n## \ud83d\udcdc License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## \ud83c\udfdb\ufe0f Institutions\n\nThis work was developed at:\n- **Georgia Institute of Technology**\n  - School of Biological Sciences\n  - School of Computer Science  \n  - Department of Biomedical Engineering\n  - School of Mechanical Engineering\n  - School of Interactive Computing\n\n## \ud83d\ude4f Acknowledgments\n\n- Meta AI for the original Segment Anything Model\n- The open-source community for tools and datasets\n- Georgia Tech for computational resources\n- All contributors and users of SAMCell\n\n---\n\n**SAMCell Team** - Making cell segmentation accessible to everyone! \ud83d\udd2c\u2728\n",
    "bugtrack_url": null,
    "license": "MIT License\n        \n        Copyright (c) 2025 Saahil Sanganeriya\n        \n        Permission is hereby granted, free of charge, to any person obtaining a copy\n        of this software and associated documentation files (the \"Software\"), to deal\n        in the Software without restriction, including without limitation the rights\n        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n        copies of the Software, and to permit persons to whom the Software is\n        furnished to do so, subject to the following conditions:\n        \n        The above copyright notice and this permission notice shall be included in all\n        copies or substantial portions of the Software.\n        \n        THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n        SOFTWARE.\n        ",
    "summary": "Generalized label-free biological cell segmentation with Segment Anything",
    "version": "1.2.0",
    "project_urls": {
        "Bug Tracker": "https://github.com/saahilsanganeriya/SAMCell/issues",
        "Documentation": "https://github.com/saahilsanganeriya/SAMCell/blob/main/README.md",
        "Homepage": "https://github.com/saahilsanganeriya/SAMCell",
        "Paper": "https://doi.org/10.1371/journal.pone.0319532",
        "Repository": "https://github.com/saahilsanganeriya/SAMCell"
    },
    "split_keywords": [
        "cell segmentation",
        " microscopy",
        " computer vision",
        " deep learning",
        " segment anything",
        " biology",
        " image analysis"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "8ad2e683cf0f151de0f607e1c6e9c44a40506e1371af72a414f2ad5d528036f3",
                "md5": "3b57ecea22b32bdf00189eb28206fb3c",
                "sha256": "49bcb1d7a056399b060d7cebe8c6bbc771f29734b07bab7ab333acf72641b772"
            },
            "downloads": -1,
            "filename": "samcell-1.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3b57ecea22b32bdf00189eb28206fb3c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 30871,
            "upload_time": "2025-10-09T23:46:34",
            "upload_time_iso_8601": "2025-10-09T23:46:34.055385Z",
            "url": "https://files.pythonhosted.org/packages/8a/d2/e683cf0f151de0f607e1c6e9c44a40506e1371af72a414f2ad5d528036f3/samcell-1.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "82f8f6e86090773e226c4ad74534ca9c131b098e0eb0d42ec217634b4d22008f",
                "md5": "b0420e9c672a02889504a8289354e0bb",
                "sha256": "38e00b4e4ab600435724aaf76150a269c574be5e9cb91ce88547e44b2c59dcbd"
            },
            "downloads": -1,
            "filename": "samcell-1.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "b0420e9c672a02889504a8289354e0bb",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 35429,
            "upload_time": "2025-10-09T23:46:35",
            "upload_time_iso_8601": "2025-10-09T23:46:35.277442Z",
            "url": "https://files.pythonhosted.org/packages/82/f8/f6e86090773e226c4ad74534ca9c131b098e0eb0d42ec217634b4d22008f/samcell-1.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-10-09 23:46:35",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "saahilsanganeriya",
    "github_project": "SAMCell",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "torch",
            "specs": [
                [
                    ">=",
                    "1.9.0"
                ]
            ]
        },
        {
            "name": "transformers",
            "specs": [
                [
                    ">=",
                    "4.26.0"
                ]
            ]
        },
        {
            "name": "numpy",
            "specs": [
                [
                    ">=",
                    "1.21.0"
                ]
            ]
        },
        {
            "name": "opencv-python-headless",
            "specs": [
                [
                    ">=",
                    "4.5.0"
                ]
            ]
        },
        {
            "name": "scikit-image",
            "specs": [
                [
                    ">=",
                    "0.19.0"
                ]
            ]
        },
        {
            "name": "scipy",
            "specs": [
                [
                    ">=",
                    "1.7.0"
                ]
            ]
        },
        {
            "name": "pandas",
            "specs": [
                [
                    ">=",
                    "1.3.0"
                ]
            ]
        },
        {
            "name": "tqdm",
            "specs": [
                [
                    ">=",
                    "4.60.0"
                ]
            ]
        },
        {
            "name": "Pillow",
            "specs": [
                [
                    ">=",
                    "8.0.0"
                ]
            ]
        },
        {
            "name": "safetensors",
            "specs": [
                [
                    ">=",
                    "0.3.0"
                ]
            ]
        },
        {
            "name": "openpyxl",
            "specs": [
                [
                    ">=",
                    "3.0.0"
                ]
            ]
        }
    ],
    "lcname": "samcell"
}
        
Elapsed time: 2.75166s