Skip to content

Commit 3154e92

Browse files
committed
Document grid search util
1 parent 173644a commit 3154e92

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

docs/source/guides/utils_module_guide.rst

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,21 @@ See `Usage section <https://adaptivemotorcontrollab.github.io/CellSeg3d/welcome.
1111

1212
You may specify the results directory for saving; afterwards you can run each action on a folder or on the currently selected layer.
1313

14+
Default Paths for Saving Results
15+
________________________________
16+
17+
Each utility saves results to a default directory under the user's home directory. The default paths are as follows:
18+
19+
* Artifact Removal: ``~/cellseg3d/artifact_removed``
20+
* Fragmentation: ``~/cellseg3d/fragmented``
21+
* Anisotropy Correction: ``~/cellseg3d/anisotropy``
22+
* Small Object Removal: ``~/cellseg3d/small_removed``
23+
* Semantic Label Conversion: ``~/cellseg3d/semantic_labels``
24+
* Instance Label Conversion: ``~/cellseg3d/instance_labels``
25+
* Thresholding: ``~/cellseg3d/threshold``
26+
* Statistics: ``~/cellseg3d/stats``
27+
* Threshold Grid Search: ``~/cellseg3d/threshold_grid_search``
28+
1429
Available actions
1530
__________________
1631

@@ -89,6 +104,18 @@ Global metrics :
89104
| Clears labels that are larger than a given threshold.
90105
| This is useful for removing artifacts that are larger than the objects of interest.
91106
107+
11. Find best threshold
108+
-----------------------
109+
| Finds the best threshold for separating objects from the background.
110+
| Requires a prediction from a model and GT labels as input.
111+
112+
.. caution::
113+
If the input prediction is not from the plugin, it will be remapped to the 0-1 range.
114+
115+
| The threshold is found by maximizing the Dice coefficient between the thresolded prediction and the binarized GT labels.
116+
117+
| The value for the best threshold will be displayed, and the prediction will be thresholded and saved with this value.
118+
92119
Source code
93120
___________
94121

napari_cellseg3d/code_plugins/plugin_convert.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,7 @@ def __init__(self, viewer: "napari.viewer.Viewer", parent=None):
857857
parent=parent,
858858
)
859859
self.do_binarize = False
860+
self.do_remap = False
860861
self.result_text = ""
861862
self.values = {}
862863

@@ -926,6 +927,8 @@ def _check_ready(self):
926927
or len(np.unique(label_data)) != 2
927928
):
928929
self.do_binarize = True
930+
if image_data.min() < 0 or image_data.max() > 1:
931+
self.do_remap = True
929932
return True
930933

931934
def _get_dice_graph(self):
@@ -945,6 +948,11 @@ def _start(self):
945948
if self.do_binarize:
946949
logger.info("Labels values are not binary, binarizing")
947950
label_data = to_semantic(label_data)
951+
if self.do_remap:
952+
logger.info(
953+
"Prediction values are not from a model. Remapping between 0 and 1"
954+
)
955+
pred_data = utils.remap_image(pred_data, new_max=1)
948956
# find best threshold
949957
search_space = np.arange(0, 1, 0.05)
950958
for i in search_space:

0 commit comments

Comments
 (0)