Skip to content

Commit e00806c

Browse files
C-Achardgityves
andauthored
Voronoi-Otsu labeling + instance segmentation code overhaul (#34)
* Instance segmentation refactor + Voronoi-Otsu - Improved code for instance segmentation - Added Voronoi-Otsu labeling from pyclesperanto TODO : credits for labeling * Disabled small removal in Voronoi-Otsu * Added new docs for instance seg * Docs + UI update - Updated welcome/README - Changed step for DoubleCounter * Update requirements.txt Fix typo * isort * Fix tests * Fixed parental issues and instance seg widget init - Fixed widgets parents that were incorrectly init - Improve use of instance seg. method classes and init * Fix inference * Added labeling tools + UI tweaks - Added tools from MLCourse to evaluate labels and auto-correct them - Instance seg benchmark notebook - Tweaked utils UI to scale according to Viewer size Co-Authored-By: gityves <[email protected]> * Testing instance methods Co-Authored-By: gityves <[email protected]> * Many fixes - Fixed monai reqs - Added custom functions for label checking - Fixed return type of voronoi_otsu and utils.resize - black * black * Complete instance method evaluation * Added pre-commit hooks * Enfore pre-commit style * Update .gitignore * Version bump * Updated project files * Fixed missing parent error * Fixed wrong value in instance sliders * Removing dask-image * Fixed erroneous dtype conversion * Update test_plugin_utils.py * Temporary test action patch * Update plugin_convert.py * Update tox.ini Added pocl for testing on GH Actions * Update tox.ini * Found existing pocl * Updated utils test to avoid Voronoi-Otsu VO is missing CL runtime * Relabeling tests * Run full suite of pre-commit hooks * Enforce style * Instance segmentation refactor + Voronoi-Otsu - Improved code for instance segmentation - Added Voronoi-Otsu labeling from pyclesperanto TODO : credits for labeling * Disabled small removal in Voronoi-Otsu * Added new docs for instance seg * isort * Fix tests * Fixed parental issues and instance seg widget init - Fixed widgets parents that were incorrectly init - Improve use of instance seg. method classes and init * Fix inference * Added labeling tools + UI tweaks - Added tools from MLCourse to evaluate labels and auto-correct them - Instance seg benchmark notebook - Tweaked utils UI to scale according to Viewer size Co-Authored-By: gityves <[email protected]> * Testing instance methods Co-Authored-By: gityves <[email protected]> * Many fixes - Fixed monai reqs - Added custom functions for label checking - Fixed return type of voronoi_otsu and utils.resize - black * black * Complete instance method evaluation * Enfore pre-commit style * Removing dask-image * Fixed erroneous dtype conversion * Update test_plugin_utils.py * Update tox.ini * Added new pre-commit hooks * Run full suite of pre-commit hooks * Enforce style * Documentation update, crop contrast fix * Update plugin_model_inference.py * Updated hooks --------- Co-authored-by: gityves <[email protected]>
1 parent 89e71dc commit e00806c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2857
-618
lines changed

.github/workflows/test_and_deploy.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ on:
88
branches:
99
- main
1010
- npe2
11+
- cy/voronoi-otsu
1112
tags:
1213
- "v*" # Push events to matching v*, i.e. v1.0, v20.15.10
1314
pull_request:
1415
branches:
1516
- main
1617
- npe2
18+
- cy/voronoi-otsu
1719
workflow_dispatch:
1820

1921
jobs:

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,8 @@ notebooks/full_plot.html
105105
*.csv
106106
*.png
107107
*.prof
108+
109+
#include test data
110+
!napari_cellseg3d/_tests/res/test.tif
111+
!napari_cellseg3d/_tests/res/test.png
112+
!napari_cellseg3d/_tests/res/test_labels.tif

.pre-commit-config.yaml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@ repos:
55
# - id: check-docstring-first
66
- id: end-of-file-fixer
77
- id: trailing-whitespace
8-
- repo: https://github.com/pycqa/isort
9-
rev: 5.12.0
10-
hooks:
11-
- id: isort
12-
args: ["--profile", "black", --line-length=79]
8+
- id: check-yaml
9+
- id: check-added-large-files
10+
- id: check-toml
11+
# - repo: https://github.com/pycqa/isort
12+
# rev: 5.12.0
13+
# hooks:
14+
# - id: isort
15+
# args: ["--profile", "black", --line-length=79]
1316
- repo: https://github.com/charliermarsh/ruff-pre-commit
1417
# Ruff version.
1518
rev: 'v0.0.262'

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,9 @@ Distributed under the terms of the [MIT] license.
151151

152152
## Acknowledgements
153153

154-
This plugin was developed by Cyril Achard, Maxime Vidal, Mackenzie Mathis. This work was funded, in part, from the Wyss Center to the [Mathis Laboratory of Adaptive Motor Control](https://www.mackenziemathislab.org/).
155-
154+
This plugin was developed by Cyril Achard, Maxime Vidal, Mackenzie Mathis.
155+
This work was funded, in part, from the Wyss Center to the [Mathis Laboratory of Adaptive Motor Control](https://www.mackenziemathislab.org/).
156+
Please refer to the documentation for full acknowledgements.
156157

157158
## Plugin base
158159
This [napari] plugin was generated with [Cookiecutter] using [@napari]'s [cookiecutter-napari-plugin] template.

docs/res/code/model_instance_seg.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,29 @@
11
model_instance_seg.py
22
===========================================
33

4+
Classes
5+
-------------
6+
7+
InstanceMethod
8+
**************************************
9+
.. autoclass:: napari_cellseg3d.code_models.model_instance_seg::InstanceMethod
10+
:members: __init__
11+
12+
ConnectedComponents
13+
**************************************
14+
.. autoclass:: napari_cellseg3d.code_models.model_instance_seg::ConnectedComponents
15+
:members: __init__
16+
17+
Watershed
18+
**************************************
19+
.. autoclass:: napari_cellseg3d.code_models.model_instance_seg::Watershed
20+
:members: __init__
21+
22+
VoronoiOtsu
23+
**************************************
24+
.. autoclass:: napari_cellseg3d.code_models.model_instance_seg::VoronoiOtsu
25+
:members: __init__
26+
427

528
Functions
629
-------------

docs/res/code/plugin_convert.rst

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@ ToSemanticUtils
1919
.. autoclass:: napari_cellseg3d.code_plugins.plugin_convert::ToSemanticUtils
2020
:members: __init__
2121

22-
InstanceWidgets
23-
**********************************
24-
.. autoclass:: napari_cellseg3d.code_plugins.plugin_convert::InstanceWidgets
25-
:members: __init__, run_method
26-
2722
ToInstanceUtils
2823
**********************************
2924
.. autoclass:: napari_cellseg3d.code_plugins.plugin_convert::ToInstanceUtils

docs/res/guides/cropping_module_guide.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ If you'd like to change the size of the volume, change the parameters as previou
3333

3434
Creating new layers
3535
---------------------------------
36-
To "zoom in" your volume, you can use the "Create new layers" checkbox to make a new layer not controlled by the plugin next
37-
time you hit Start. This way, you can first select your region of interest by using the tool as described above,
38-
the enable the option, select the cropped layer, and define a smaller crop size to have easier access to your region of interest.
36+
To "zoom in" your volume, you can use the "Create new layers" checkbox to make a new cropping layer controlled by the sliders
37+
next time you hit Start. This way, you can first select your region of interest by using the tool as described above,
38+
then enable the option, select the cropped region produced before as the input layer, and define a smaller crop size in order to crop within your region of interest.
3939

4040
Interface & functionalities
4141
---------------------------------------------------------------

docs/res/guides/utils_module_guide.rst

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,21 @@ Label conversion utility guide
44
==================================
55

66
This utility will let you convert labels to various different formats.
7+
78
You will have to specify the results directory for saving; afterwards you can run each action on a folder or on the currently selected layer.
89

910
You can :
1011

12+
* Crop 3D volumes :
13+
Please refer to :ref:`cropping_module_guide` for a guide on using the cropping utility.
14+
1115
* Convert to instance labels :
12-
This will convert 0/1 semantic labels to instance label, with a unique ID for each object using the watershed method.
16+
This will convert 0/1 semantic labels to instance label, with a unique ID for each object.
17+
The available methods for this are :
1318

19+
* Connected components : simple method that will assign a unique ID to each connected component. Does not work well for touching objects (objects will often be fused), works for anisotropic volumes.
20+
* Watershed : method based on topographic maps. Works well for touching objects and anisotropic volumes; touching objects may be fused.
21+
* Voronoi-Otsu : method based on Voronoi diagrams. Works well for touching objects but only for isotropic volumes.
1422
* Convert to semantic labels :
1523
This will convert instance labels with unique IDs per object into 0/1 semantic labels, for example for training.
1624

docs/res/welcome.rst

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,22 +38,28 @@ You can install `napari-cellseg3d` via [pip]:
3838

3939
``pip install napari-cellseg3d``
4040

41-
For local installation, please run:
41+
For local installation after cloning, please run in the CellSeg3D folder:
4242

4343
``pip install -e .``
4444

4545
Requirements
4646
--------------------------------------------
4747

48+
.. note::
49+
A **CUDA-capable GPU** is not needed but **very strongly recommended**, especially for training and possibly inference.
50+
4851
.. important::
49-
A **CUDA-capable GPU** is not needed but **very strongly recommended**, especially for training.
52+
This package requires you have napari installed with PyQt5 or PySide2 first.
53+
If you do not have a Qt backend you can use :
5054

51-
This package requires you have napari installed first.
55+
``pip install napari-cellseg3d[all]``
56+
to install PyQt5 by default.
5257

53-
It also depends on PyTorch and some optional dependencies of MONAI. These come in the pip package above, but if
58+
It also depends on PyTorch and some optional dependencies of MONAI. These come in the pip package as requirements, but if
5459
you need further assistance see below.
5560

5661
* For help with PyTorch, please see `PyTorch's website`_ for installation instructions, with or without CUDA depending on your hardware.
62+
Depending on your setup, you might wish to install torch first.
5763

5864
* If you get errors from MONAI regarding missing readers, please see `MONAI's optional dependencies`_ page for instructions on getting the readers required by your images.
5965

@@ -70,14 +76,13 @@ To use the plugin, please run:
7076

7177
Then go into Plugins > napari-cellseg3d, and choose which tool to use:
7278

73-
7479
- **Review**: 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
7580
- **Inference**: This module allows you to use pre-trained segmentation algorithms on volumes to automatically label cells
7681
- **Training**: This module allows you to train segmentation algorithms from labeled volumes
7782
- **Utilities**: This module allows you to use several utilities, e.g. to crop your volumes and labels, compute prediction scores or convert labels
7883
- **Help/About...** : Quick access to version info, Github page and docs
7984

80-
See above for links to detailed guides regarding the usage of the modules.
85+
See the documentation for links to detailed guides regarding the usage of the modules.
8186

8287
Acknowledgments & References
8388
---------------------------------------------
@@ -90,24 +95,29 @@ We also provide a model that was trained in-house on mesoSPIM nuclei data in col
9095

9196
This plugin mainly uses the following libraries and software:
9297

93-
* `napari website`_
98+
* `napari`_
9499

95-
* `PyTorch website`_
100+
* `PyTorch`_
96101

97-
* `MONAI project website`_ (various models used here are credited `on their website`_)
102+
* `MONAI project`_ (various models used here are credited `on their website`_)
98103

104+
* `pyclEsperanto`_ (for the Voronoi Otsu labeling) by Robert Haase
105+
106+
* A custom re-implementation of the `WNet model`_ by Xia and Kulis [#]_
99107

100108
.. _Mathis Laboratory of Adaptive Motor Control: http://www.mackenziemathislab.org/
101109
.. _Wyss Center: https://wysscenter.ch/
102110
.. _TRAILMAP project on GitHub: https://github.com/AlbertPun/TRAILMAP
103-
.. _napari website: https://napari.org/
104-
.. _PyTorch website: https://pytorch.org/
105-
.. _MONAI project website: https://monai.io/
111+
.. _napari: https://napari.org/
112+
.. _PyTorch: https://pytorch.org/
113+
.. _MONAI project: https://monai.io/
106114
.. _on their website: https://docs.monai.io/en/stable/networks.html#nets
107-
115+
.. _pyclEsperanto: https://github.com/clEsperanto/pyclesperanto_prototype
116+
.. _WNet model: https://arxiv.org/abs/1711.08506
108117

109118
.. rubric:: References
110119

111120
.. [#] Mapping mesoscale axonal projections in the mouse brain using a 3D convolutional network, Friedmann et al., 2020 ( https://pnas.org/cgi/doi/10.1073/pnas.1918465117 )
112121
.. [#] The mesoSPIM initiative: open-source light-sheet microscopes for imaging cleared tissue, Voigt et al., 2019 ( https://doi.org/10.1038/s41592-019-0554-0 )
113122
.. [#] MONAI Project website ( https://monai.io/ )
123+
.. [#] W-Net: A Deep Model for Fully Unsupervised Image Segmentation, Xia and Kulis, 2018 ( https://arxiv.org/abs/1711.08506 )

napari_cellseg3d/_tests/pytest.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[pytest]
2+
qt_api=pyqt5

0 commit comments

Comments
 (0)