-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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]>
- Loading branch information
Showing
43 changed files
with
2,857 additions
and
618 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[pytest] | ||
qt_api=pyqt5 |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from pathlib import Path | ||
|
||
import numpy as np | ||
from tifffile import imread | ||
|
||
from napari_cellseg3d.dev_scripts import artefact_labeling as al | ||
from napari_cellseg3d.dev_scripts import correct_labels as cl | ||
from napari_cellseg3d.dev_scripts import evaluate_labels as el | ||
|
||
res_folder = Path(__file__).resolve().parent / "res" | ||
image_path = res_folder / "test.tif" | ||
image = imread(str(image_path)) | ||
|
||
labels_path = res_folder / "test_labels.tif" | ||
labels = imread(str(labels_path)) # .astype(np.int32) | ||
|
||
|
||
def test_artefact_labeling(): | ||
output_path = str(res_folder / "test_artifacts.tif") | ||
al.create_artefact_labels(image, labels, output_path=output_path) | ||
assert Path(output_path).is_file() | ||
|
||
|
||
def test_artefact_labeling_utils(): | ||
crop_test = al.crop_image(image) | ||
assert isinstance(crop_test, np.ndarray) | ||
output_path = str(res_folder / "test_cropped.tif") | ||
al.crop_image_path(image, path_image_out=output_path) | ||
assert Path(output_path).is_file() | ||
|
||
|
||
def test_correct_labels(): | ||
output_path = res_folder / "test_correct" | ||
output_path.mkdir(exist_ok=True, parents=True) | ||
cl.relabel_non_unique_i( | ||
labels, str(output_path / "corrected.tif"), go_fast=True | ||
) | ||
|
||
|
||
def test_relabel(make_napari_viewer): | ||
viewer = make_napari_viewer() | ||
cl.relabel( | ||
str(image_path), | ||
str(labels_path), | ||
go_fast=True, | ||
viewer=viewer, | ||
test=True, | ||
) | ||
|
||
|
||
def test_evaluate_model_performance(): | ||
el.evaluate_model_performance(labels, labels, print_details=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,32 @@ | ||
from napari_cellseg3d.code_plugins.plugin_utilities import Utilities | ||
from pathlib import Path | ||
|
||
import numpy as np | ||
from tifffile import imread | ||
|
||
from napari_cellseg3d.code_plugins.plugin_utilities import ( | ||
UTILITIES_WIDGETS, | ||
Utilities, | ||
) | ||
|
||
|
||
def test_utils_plugin(make_napari_viewer): | ||
view = make_napari_viewer() | ||
widget = Utilities(view) | ||
|
||
im_path = str(Path(__file__).resolve().parent / "res/test.tif") | ||
image = imread(im_path) | ||
view.add_image(image) | ||
view.add_labels(image.astype(np.uint8)) | ||
|
||
view.window.add_dock_widget(widget) | ||
for i, utils_name in enumerate(UTILITIES_WIDGETS.keys()): | ||
widget.utils_choice.setCurrentIndex(i) | ||
assert isinstance( | ||
widget.utils_widgets[i], UTILITIES_WIDGETS[utils_name] | ||
) | ||
if utils_name == "Convert to instance labels": | ||
# to avoid issues with Voronoi-Otsu missing runtime | ||
menu = widget.utils_widgets[i].instance_widgets.method_choice | ||
menu.setCurrentIndex(menu.currentIndex() + 1) | ||
|
||
widget.utils_widgets[i]._start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.