Segment Anything for Microscopy

Anwai Archit, Sushmita Nair, Nabeel Khalid, Paul Hilt, Vikas Rajashekar, Marei Freitag, Sagnik Gupta, Andreas Dengel, Sheraz Ahmed, Constantin PapebioRxiv 2023

Abstract

We present Segment Anything for Microscopy, a tool for interactive and automatic segmentation and tracking of objects in multi-dimensional microscopy data. Our method is based on Segment Anything, a vision foundation model for image segmentation. We extend it by training specialized models for microscopy data that significantly improve segmentation quality for a wide range of imaging conditions. We also implement annotation tools for interactive (volumetric) segmentation and tracking, that speed up data annotation significantly compared to established tools. Our work constitutes the first application of vision foundation models to microscopy, laying the groundwork for solving image analysis problems in these domains with a small set of powerful deep learning architectures.

Introduction

The segmentation of biological structures—such as nuclei, cells, and organelles—is a fundamental task in microscopy image analysis. Despite its importance, the field remains fragmented due to the vast diversity of imaging modalities, including fluorescence, phase contrast, and electron microscopy (EM). Models trained on one modality often fail to generalize to others, necessitating the labor-intensive creation of custom datasets or the use of specialized tools like CellPose, which may still struggle with novel data types.

To bridge this "generalization gap," we leverage Vision Foundation Models (VFMs). Specifically, we adapt Meta’s Segment Anything Model (SAM) for the microscopy domain. We introduce micro_sam, a framework that combines finetuned generalist models with an interactive annotation tool designed to accelerate biological research.

The micro_sam Framework

The micro_sam tool extends the original SAM architecture through three primary innovations:

  1. Iterative Finetuning: We developed a training scheme that simulates human interaction. The model receives an image, generates a prediction, and is then provided with "corrective" positive or negative point prompts to refine its weights.
  2. Generalist Models: We trained separate generalist models for Light Microscopy (LM) and Electron Microscopy (EM) using a diverse "superset" of public datasets, including LiveCELL, TissueNet, and MitoEM.
  3. Interactive Tooling: The framework is integrated into the napari image viewer. By implementing tiled embeddings and precomputation, we enable lag-free interactive segmentation on standard consumer hardware.
Overview of the micro_sam workflow, illustrating the integration of diverse microscopy datasets, iterative finetuning, and interactive annotation.

Results and Evaluation

Our evaluation demonstrates that finetuning SAM specifically for microscopy significantly enhances its performance, particularly in crowded biological environments where the default model often fails to distinguish individual boundaries.

Visual Performance: As shown in the figure below, the finetuned models provide much tighter and more accurate masks compared to the default SAM, which often produces "blobs" that merge adjacent cells in both LM and EM modalities.

Comparison of segmentation masks generated by the default SAM versus the finetuned micro_sam across various LM and EM modalities.

Efficiency and Speed: In 2D organoid segmentation, micro_sam reduced annotation time to 0.3 seconds per object—a 10x speedup over manual annotation and a significant improvement over CellPose (1.3s). For 3D volumetric EM data, the tool was nearly twice as fast as standard methods like ilastik carving.

Generalization: The models showed robust performance on "unseen" datasets, such as CovidIF and histopathology images, confirming the effectiveness of the generalist training approach.

Discussion and Future Work

A key finding of our study is that finetuning the Image Encoder yields the most substantial performance gains, as it allows the model to better extract domain-specific features. Furthermore, we observed high data efficiency: finetuning on as little as 2-5% of a dataset captures the majority of quality improvements, making "in-the-loop" training feasible for researchers with limited annotated data.

However, challenges remain. Generalizing in EM is inherently difficult due to hierarchical structures (e.g., organelles within cells). Our current EM generalist struggles with small structures like mitochondria, suggesting a continued need for specialized models in certain contexts. Future work will focus on smaller architectures like ViT-Tiny to further reduce hardware requirements.

Conclusion

micro_sam represents a significant step toward a unified foundation for microscopy image analysis. By adapting SAM to the specific needs of the biological community, we provide a tool that is both highly accurate and significantly faster than existing solutions, paving the way for more efficient large-scale biological studies.

Summary updated

BibTeX
@misc{archit2023segment,
  author = {Anwai Archit and Sushmita Nair and Nabeel Khalid and Paul Hilt and Vikas Rajashekar and Marei Freitag and Sagnik Gupta and Andreas Dengel and Sheraz Ahmed and Constantin Pape},
  title = {{Segment Anything for Microscopy}},
  year = {2023},
  doi = {10.1101/2023.08.21.554208},
  howpublished = {bioRxiv},
}
Figure