Skip to content

Cell Segmentation Guide

This guide helps you choose the optimal segmentation method for your bacterial images and achieve the best possible cell detection results.

🎯 Overview

mAIcrobe offers four main segmentation approaches:

Method Type Training Required Speed Accuracy
🌟 StarDist Deep Learning βœ… Custom model Medium High
πŸ”¬ Cellpose Deep Learning ❌ Pre-trained Medium High
🧠 U-Net Deep Learning βœ… Custom model Medium High
⚑ Thresholding Classical ❌ None Fast Medium

Although StarDist and U-Net models require custom training, mAIcrobe includes a pre-trained models for several bacterial species and modalities. The models are downloaded from our GitHub repository on first use and stored inside your user folder under .maicrobecache.

Tip: You can always refine the segmentation manually using napari’s built-in label editing tools. Check the official napari Labels layer documentation for more details on using Labels layers.


🌟 StarDist Models

Best for: Star-convex shaped cells (most bacteria)

Key Features

  • 🎯 Purpose: Deep learning-based segmentation for star-convex shapes
  • πŸ”§ Requirement: Custom trained model needed.

Getting Started

  1. Learn more: Check the StarDist paper and repository
  2. Training: Use our example notebook at notebooks/StarDistSegmentationTraining.ipynb Notebook link: https://github.com/HenriquesLab/mAIcrobe/blob/main/notebooks/StarDistSegmentationTraining.ipynb
  3. Examples: See StarDist training examples

Note: mAIcrobe provides a pre-trained StarDist model for S. aureus SIM images stained with NileRed membrane dye. Select "StarDist S.aureus SIM" in the segmentation widget.


πŸ”¬ Cellpose Models

Best for: General cell segmentation across diverse cell types

Key Features

  • 🎯 Purpose: Universal deep learning segmentation model
  • πŸš€ Ready to use: Pre-trained cyto3 model included
  • 🌐 Versatile: Trained on diverse cell types and imaging modalities

Getting Started

  1. Learn more: Check the Cellpose paper and repository
  2. First run: Model weights download automatically on first use (can take several minutes depending on your internet connection)
  3. Usage: Select "CellPose cyto3" in the segmentation widget

Tip: Cellpose is great for getting started quickly without training custom models.


🧠 U-Net Models

Best for: Custom applications with specific imaging conditions

Key Features

  • 🎯 Purpose: Convolutional neural network
  • πŸ”§ Format: Requires Keras model files (.keras)
  • 🎨 Flexible: Can be trained for specific cell types and conditions
  • βš™οΈ ZeroCostDL4Mic: Recommended tool for training U-Net models that integrate with mAIcrobe

Model Requirements

Your U-Net model should output:

  • 0: Background
  • 1: Cell boundary
  • 2: Cell interior

mAIcrobe converts this to individual cell labels using scikit-image watershed segmentation.

Note: mAIcrobe provides several pre-trained U-Net models for different bacterial species and imaging modalities. In the compute_label widget, select from the following options:

  • "Ph.C. S. pneumo" : Phase contrast S. pneumoniae
  • "WF FtsZ B. subtilis": Widefield fluorescence B. subtilis expressing FtsZ-GFP
  • "Unet S. aureus": Membrane labeled SIM S. aureus

Getting Started

  1. Learn more: Read the U-Net paper
  2. Training: Use ZeroCostDL4Mic
  3. Technical details: See watershed documentation

⚑ Thresholding-Based Methods

Best for: Quick analysis without training requirements

Key Features

  • πŸš€ Speed: Fastest segmentation method
  • πŸ”§ No training: Classical image processing
  • βš–οΈ Trade-off: Lower accuracy for complex images

Available Methods

πŸ“Š Isodata Thresholding

  • Type: Global automatic threshold
  • How it works: Analyzes image histogram to find optimal threshold
  • Best for: Images with clear intensity separation. Phase contrast is a typical example.
  • Reference: scikit-image documentation

🎯 Local Average Thresholding

  • Type: Adaptive local threshold
  • How it works: Computes threshold based on local neighborhood
  • Best for: Images with uneven illumination
  • Reference: scikit-image documentation

Processing Pipeline

  1. Threshold β†’ Binary image
  2. Distance transform β†’ Separate touching cells. See scipy distance transform docs
  3. Watershed β†’ Individual cell labels. See scikit-image watershed docs.

πŸ“ Validation and Quality Control

βœ… Manual Validation Checklist

Always validate segmentation results:

  • Sample size: Check 50-100 cells randomly
  • Visual inspection: Look for common segmentation errors:
    • Under-segmentation (multiple cells as one)
    • Over-segmentation (one cell split into multiple)
    • Boundary accuracy
    • Missing cells

πŸ“Š Automated Quality Metrics

Key indicators to monitor:

  • Cell count consistency across similar images
  • Size distribution of segmented cells - look for outliers
  • Circularity of segmented cells - should be species-appropriate |

πŸ“š Further Reading

πŸ“– Scientific References

πŸ› οΈ Technical Documentation


Next: Learn how to analyze your segmented cells in the Cell Analysis Guide πŸ”¬