Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions .napari/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

<!---->

<!--
TODO : complete
This file is designed to provide you with a starting template for documenting
Expand All @@ -10,6 +10,7 @@ The sections below are given as a guide for the flow of information only, and
are in no way prescriptive. You should feel free to merge, remove, add and
rename sections at will to make this document work best for your plugin.
-->

## Description

A napari plugin for 3D cell segmentation: training, inference, and data review. In particular, this project was developed for analysis of mesoSPIM-acquired (cleared tissue + lightsheet) datasets.
Expand Down Expand Up @@ -46,6 +47,7 @@ Here is an example of an mp4 video embedded this way.

https://user-images.githubusercontent.com/17995243/120088305-6c093380-c132-11eb-822d-620e81eb5f0e.mp4
-->

## Intended Audience & Supported Data

This plugin requires basic knowledge in machine learning;
Expand All @@ -68,16 +70,18 @@ make sure to mention this.
If you know of researchers, groups or labs using your plugin, or if it has been cited
anywhere, feel free to also include this information here.
-->

## Quickstart

Install from pip with `pip install napari-cellseg3d`

OR

- Install napari from pip with `pip install "napari[all]"`,
then from the “Plugins” menu within the napari application, select “Install/Uninstall Package(s)...”
then from the “Plugins” menu within the napari application, select “Install/Uninstall Package(s)...”
- Copy `napari-cellseg3d` and paste it where it says “Install by name/url…”
- Click “Install”

<!--


Expand All @@ -91,6 +95,7 @@ quick overview of the plugin's functionality, but you should definitely link out
more complex and in-depth tutorials highlighting any intricacies of your plugin, and
more detailed documentation if you have it.
-->

## Additional Install Steps

**Python >= 3.8 required**
Expand All @@ -114,10 +119,12 @@ over in `setup.cfg`. However, if your plugin has any more complex dependencies,
requires any additional preparation before (or after) installation, you should add
this information here.
-->

## Getting Help

If you would like to report an issue with the plugin,
please open an [issue on Github](https://github.com/AdaptiveMotorControlLab/CellSeg3D/issues)

<!--
This section should point users to your preferred support tools, whether this be raising
an issue on GitHub, asking a question on image.sc, or using some other method of contact.
Expand All @@ -127,7 +134,6 @@ here.

## How to Cite


<!--
Many plugins may be used in the course of published (or publishable) research, as well as
during conference talks and other public facing events. If you'd like to be cited in
Expand Down
47 changes: 25 additions & 22 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,37 +1,40 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v6.0.0
hooks:
# - id: check-docstring-first
- id: end-of-file-fixer
- id: trailing-whitespace
- id: check-yaml
- id: check-toml
# - id: check-added-large-files
# args: [--maxkb=5000]
# - repo: https://github.com/pycqa/isort
# rev: 5.12.0
# hooks:
# - id: isort
# args: ["--profile", "black", --line-length=79]
- repo: https://github.com/charliermarsh/ruff-pre-commit
# Ruff version.
rev: 'v0.5.6'
# args: [--maxkb=5000]

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.13
hooks:
- id: ruff
args: [ --fix, --exit-non-zero-on-fix ]
- repo: https://github.com/psf/black
rev: 24.8.0
args: [--fix, --unsafe-fixes, --exit-non-zero-on-fix]

- id: ruff-format

- repo: https://github.com/executablebooks/mdformat
rev: 1.0.0
hooks:
- id: black
args: [--line-length=79]
- id: mdformat
additional_dependencies:
- mdformat-myst

- repo: https://github.com/tox-dev/pyproject-fmt
rev: v2.21.2
hooks:
- id: pyproject-fmt

- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.25
hooks:
- id: validate-pyproject

- repo: https://github.com/tlambert03/napari-plugin-checks
rev: v0.3.0
hooks:
- id: napari-plugin-checks
# https://mypy.readthedocs.io/en/stable/introduction.html
# you may wish to add this as well!
# - repo: https://github.com/pre-commit/mirrors-mypy
# rev: v0.910-1
# hooks:
# - id: mypy
30 changes: 15 additions & 15 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ appearance, race, religion, or sexual identity and orientation.
Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
- Using welcoming and inclusive language
- Being respectful of differing viewpoints and experiences
- Gracefully accepting constructive criticism
- Focusing on what is best for the community
- Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
- The use of sexualized language or imagery and unwelcome sexual attention or
advances
- Trolling, insulting/derogatory comments, and personal or political attacks
- Public or private harassment
- Publishing others' private information, such as a physical or electronic
address, without explicit permission
- Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities

Expand Down Expand Up @@ -70,7 +70,7 @@ members of the project's leadership.
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html

[homepage]: https://www.contributor-covenant.org

For answers to common questions about this code of conduct, see
https://www.contributor-covenant.org/faq

[homepage]: https://www.contributor-covenant.org
77 changes: 36 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# CellSeg3D: self-supervised (and supervised) 3D cell segmentation, primarily for mesoSPIM data!

<!-- [![napari hub](https://img.shields.io/endpoint?url=https://api.napari-hub.org/shields/napari-cellseg3d)](https://www.napari-hub.org/plugins/napari_cellseg3d) -->

[![PyPI](https://img.shields.io/pypi/v/napari-cellseg3d.svg?color=green)](https://pypi.org/project/napari-cellseg3d)
[![Downloads](https://static.pepy.tech/badge/napari-cellseg3d)](https://pepy.tech/project/napari-cellseg3d)
[![Downloads](https://static.pepy.tech/badge/napari-cellseg3d/month)](https://pepy.tech/project/napari-cellseg3d)
Expand All @@ -9,16 +11,13 @@

<img src="https://images.squarespace-cdn.com/content/v1/57f6d51c9f74566f55ecf271/838605d0-9723-4e43-83cd-6dbfe4adf36b/cellseg-logo.png?format=1500w" title="cellseg3d" alt="cellseg3d logo" width="150" align="right" vspace = "80"/>


**A package for 3D cell segmentation with deep learning, including a napari plugin**: training, inference, and data review. In particular, this project was developed for analysis of confocal and mesoSPIM-acquired (cleared tissue + lightsheet) tissue datasets, but is not limited to this type of data. [Check out our publication for more information!](https://elifesciences.org/articles/99848)


![demo](https://images.squarespace-cdn.com/content/v1/57f6d51c9f74566f55ecf271/0d16a71b-3ff2-477a-9d83-18d96cb1ce28/full_demo.gif?format=500w)


## Installation

💻 See the [Installation page](https://adaptivemotorcontrollab.github.io/CellSeg3D/welcome.html) in the documentation for detailed instructions.
💻 See the [Installation page](https://adaptivemotorcontrollab.github.io/CellSeg3D/welcome.html) in the documentation for detailed instructions.

## Documentation

Expand All @@ -33,21 +32,22 @@ pip install napari_cellseg3d
```

To use the plugin, please run:

```
napari
```

Then go into `Plugins > napari_cellseg3d`, and choose which tool to use.

- **Review (label)**: This module allows you to review your labels, from predictions or manual labeling, and correct them if needed. It then saves the status of each file in a csv, for easier monitoring.
- **Inference**: This module allows you to use pre-trained segmentation algorithms on volumes to automatically label cells and compute statistics.
- **Train**: This module allows you to train segmentation algorithms from labeled volumes.
- **Train**: This module allows you to train segmentation algorithms from labeled volumes.
- **Utilities**: This module allows you to perform several actions like cropping your volumes and labels dynamically, by selecting a fixed size volume and moving it around the image; fragment images into smaller cubes for training; or converting labels from instance to segmentation and the opposite.

## Why use CellSeg3D?

The strength of our approach is we can match supervised model performance with purely self-supervised learning, meaning users don't need to spend (hundreds) of hours on annotation. Here is a quick look of our key results. TL;DR see panel **f**, which shows that with minmal input data we can outperform supervised models:


![FIG1 (1)](https://github.com/user-attachments/assets/0d970b45-79ff-4c58-861f-e1e7dc9abc65)

**Figure 1. Performance of 3D Semantic and Instance Segmentation Models.**
Expand All @@ -59,7 +59,6 @@ F1-score is computed from the Intersection over Union (IoU) with ground truth la
**c:** View of 3D instance labels from supervised models, as noted, for visual cortex volume in b evaluation.
**d:** Illustration of our WNet3D architecture showcasing the dual 3D U-Net structure with our modifications.


## News

### **CellSeg3D now published at eLife**
Expand All @@ -69,15 +68,19 @@ Read the [article here !](https://elifesciences.org/articles/99848)
### **New version: v0.2.2**

- v0.2.2:

- Updated the Colab Notebooks for training and inference
- New models available in the inference demo notebook
- CRF optional post-processing adjustments (and pip install directly)

- v0.2.1:

- Updated plugin default behaviors across the board to be more readily applicable to demo data
- Threshold value in inference is now automatically set by default according to performance on demo data on a per-model basis
- Added a grid search utility to find best thresholds for supervised models

- v0.2.0:

- Changed project name to "napari_cellseg3d" to avoid setuptools deprecation
- Small API changes for training/inference from a script
- Some fixes to WandB integration and csv saving after training
Expand All @@ -97,7 +100,6 @@ Previous additions:
- New utilities
- Many small improvements and many bug fixes


## Requirements

**Compatible with Python 3.8 to 3.10.**
Expand All @@ -118,39 +120,38 @@ Please reach out if you have any issues with the installation, we will be happy

To avoid issues when installing on the ARM64 architecture, please follow these steps.

1) Create a new conda env using the provided conda/napari_CellSeg3D_ARM64.yml file :
1. Create a new conda env using the provided conda/napari_CellSeg3D_ARM64.yml file :

git clone https://github.com/AdaptiveMotorControlLab/CellSeg3d.git
cd CellSeg3d
conda env create -f conda/napari_CellSeg3D_ARM64.yml
conda activate napari_CellSeg3D_ARM64


2) Install a Qt backend (PySide or PyQt5)
3) Launch napari, the plugin should be available in the plugins menu.
```
git clone https://github.com/AdaptiveMotorControlLab/CellSeg3d.git
cd CellSeg3d
conda env create -f conda/napari_CellSeg3D_ARM64.yml
conda activate napari_CellSeg3D_ARM64
```

1. Install a Qt backend (PySide or PyQt5)

1. Launch napari, the plugin should be available in the plugins menu.

## Issues

**Help us make the code better by reporting issues and adding your feature requests!**


If you encounter any problems, please [file an issue] along with a detailed description.

## Testing

You can generate docs locally by running ``make html`` in the docs/ folder.
You can generate docs locally by running `make html` in the docs/ folder.

Before testing, install all requirements using ``pip install napari-cellseg3d[test]``.
Before testing, install all requirements using `pip install napari-cellseg3d[test]`.

``pydensecrf`` is also required for testing.
`pydensecrf` is also required for testing.

To run tests locally:

- Locally : run ``pytest napari_cellseg3d\_tests`` in the plugin folder.
- Locally with coverage : In the plugin folder, run ``coverage run --source=napari_cellseg3d -m pytest`` then ``coverage xml`` to generate a .xml coverage file.
- With tox : run ``tox`` in the plugin folder (will simulate tests with several python and OS configs, requires substantial storage space)
- Locally : run `pytest napari_cellseg3d\_tests` in the plugin folder.
- Locally with coverage : In the plugin folder, run `coverage run --source=napari_cellseg3d -m pytest` then `coverage xml` to generate a .xml coverage file.
- With tox : run `tox` in the plugin folder (will simulate tests with several python and OS configs, requires substantial storage space)

## Contributing

Expand All @@ -170,23 +171,6 @@ Distributed under the terms of the [MIT] license.

"napari-cellseg3d" is free and open source software.

[napari-hub]: https://www.napari-hub.org/plugins/napari-cellseg3d

[file an issue]: https://github.com/AdaptiveMotorControlLab/CellSeg3D/issues
[napari]: https://github.com/napari/napari
[Cookiecutter]: https://github.com/audreyr/cookiecutter
[@napari]: https://github.com/napari
[MIT]: http://opensource.org/licenses/MIT
[cookiecutter-napari-plugin]: https://github.com/napari/cookiecutter-napari-plugin
[tox]: https://tox.readthedocs.io/en/latest/
[pip]: https://pypi.org/project/pip/
[PyPI]: https://pypi.org/
[Installation page]: https://adaptivemotorcontrollab.github.io/CellSeg3D/source/guides/installation_guide.html
[the PyTorch website for installation instructions]: https://pytorch.org/get-started/locally/
[PyTorch]: https://pytorch.org/get-started/locally/
[MONAI's optional dependencies]: https://docs.monai.io/en/stable/installation.html#installing-the-recommended-dependencies
[MONAI]: https://docs.monai.io/en/stable/installation.html#installing-the-recommended-dependencies

## Citation

```
Expand Down Expand Up @@ -220,3 +204,14 @@ Please refer to the documentation for full acknowledgements.
## Plugin base

This [napari] plugin was generated with [Cookiecutter] using [@napari]'s [cookiecutter-napari-plugin] template.

[@napari]: https://github.com/napari
[cookiecutter]: https://github.com/audreyr/cookiecutter
[cookiecutter-napari-plugin]: https://github.com/napari/cookiecutter-napari-plugin
[file an issue]: https://github.com/AdaptiveMotorControlLab/CellSeg3D/issues
[mit]: http://opensource.org/licenses/MIT
[monai]: https://docs.monai.io/en/stable/installation.html#installing-the-recommended-dependencies
[monai's optional dependencies]: https://docs.monai.io/en/stable/installation.html#installing-the-recommended-dependencies
[napari]: https://github.com/napari/napari
[pytorch]: https://pytorch.org/get-started/locally/
[the pytorch website for installation instructions]: https://pytorch.org/get-started/locally/
5 changes: 3 additions & 2 deletions docs/TODO.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
[//]: # (
\[//\]: # (
TODO:

- [ ] Add a way to get the current version of the library
- [x] Update all modules
- [x] Better WNet3D tutorial
- [x] Setup GH Actions
- [ ] Add a bibliography
)
)
2 changes: 1 addition & 1 deletion docs/source/guides/training_wnet.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ The WNet3D **does not require a large amount of data to train**, but **choosing

You may find below some guidelines, based on our own data and testing.

The WNet3D is a self-supervised learning approach for 3D cell segmentation, and relies on the assumption that structural and morphological features of cells can be inferred directly from unlabeled data. This involves leveraging inherent properties such as spatial coherence and local contrast in imaging volumes to distinguish cellular structures. This approach assumes that meaningful representations of cellular boundaries and nuclei can emerge solely from raw 3D volumes. Thus, we strongly recommend that you use WNet3D on stacks that have clear foreground/background segregation and limited noise. Even if your final samples have noise, it is best to train on data that is as clean as you can.
The WNet3D is a self-supervised learning approach for 3D cell segmentation, and relies on the assumption that structural and morphological features of cells can be inferred directly from unlabeled data. This involves leveraging inherent properties such as spatial coherence and local contrast in imaging volumes to distinguish cellular structures. This approach assumes that meaningful representations of cellular boundaries and nuclei can emerge solely from raw 3D volumes. Thus, we strongly recommend that you use WNet3D on stacks that have clear foreground/background segregation and limited noise. Even if your final samples have noise, it is best to train on data that is as clean as you can.


.. important::
Expand Down
2 changes: 1 addition & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ All credits to the original authors of the data.
You can install, launch `napari`, activate the CellSeg3D plugin app, and drag & drop this volume into the canvas.
Then, for example, run the `Inference` module with one of our models.

See [CellSeg3D documentation](https://adaptivemotorcontrollab.github.io/CellSeg3D/welcome.html) for more details.
See [CellSeg3D documentation](https://adaptivemotorcontrollab.github.io/CellSeg3D/welcome.html) for more details.
Loading
Loading