Skip to content

Commit f66764c

Browse files
committed
intuitive visible settings, finish saving denoise image
1 parent d7597fa commit f66764c

File tree

1 file changed

+36
-15
lines changed

1 file changed

+36
-15
lines changed

active_plugins/runcellpose.py

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@
6767
may take some time. If you want to use a GPU to run the model, you'll need a compatible version of PyTorch and a
6868
supported GPU. Instructions are avaiable at this link: {CUDA_LINK}
6969
70+
Note that RunCellpose supports the Cellpose 3 functionality of using image restoration models to improve the input images before segmentation for both Docker and Python methods.
71+
However, it only supports saving out or visualizing the intermediate restored images when using the Python method.
72+
7073
Stringer, C., Wang, T., Michaelos, M. et al. Cellpose: a generalist algorithm for cellular segmentation. Nat Methods 18, 100–106 (2021). {Cellpose_link}
7174
Kevin J. Cutler, Carsen Stringer, Paul A. Wiggins, Joseph D. Mougous. Omnipose: a high-precision morphology-independent solution for bacterial cell segmentation. bioRxiv 2021.11.03.467199. {Omnipose_link}
7275
============ ============ ===============
@@ -435,6 +438,19 @@ def set_directory_fn(path):
435438
N.b. for upsampling it is essential that the "Expected diameter" setting is correct for the input images
436439
""",
437440
)
441+
self.denoise_image = Binary(
442+
text="Save preprocessed image?",
443+
value=False,
444+
doc="""
445+
If enabled, the intermediate preprocessed image will be recorded as a new image.
446+
This is only supported for Python mode of Cellpose 3.
447+
""",
448+
)
449+
self.denoise_name = ImageName(
450+
"Name the preprocessed image",
451+
"Preprocessed",
452+
doc="Enter the name you want to call the preprocessed image produced by this module.",
453+
)
438454

439455
def settings(self):
440456
return [
@@ -471,10 +487,18 @@ def settings(self):
471487
self.probability_rescale_setting,
472488
self.denoise,
473489
self.denoise_type,
490+
self.denoise_image,
491+
self.denoise_name,
474492
]
475493

476494
def visible_settings(self):
477-
vis_settings = [self.rescale, self.docker_or_python, self.cellpose_version]
495+
vis_settings = [self.rescale, self.cellpose_version]
496+
497+
if self.cellpose_version.value == 'omnipose': # omnipose only supports Python, not Docker
498+
self.docker_or_python.value = "Python"
499+
vis_settings += [self.omni]
500+
else:
501+
vis_settings += [self.docker_or_python]
478502

479503
if self.docker_or_python.value == "Docker":
480504
if self.cellpose_version.value == 'v2':
@@ -496,9 +520,6 @@ def visible_settings(self):
496520

497521
vis_settings += [self.x_name]
498522

499-
if self.docker_or_python.value == "Python":
500-
vis_settings += [self.omni]
501-
502523
if self.mode.value != "nuclei":
503524
vis_settings += [self.supply_nuclei]
504525
if self.supply_nuclei.value:
@@ -520,6 +541,11 @@ def visible_settings(self):
520541
self.y_name,
521542
self.save_probabilities,
522543
]
544+
if self.save_probabilities.value:
545+
vis_settings += [self.probabilities_name]
546+
if self.docker_or_python.value == 'Python':
547+
vis_settings += [self.probability_rescale_setting]
548+
523549
if self.cellpose_version.value in ['v2','v3']:
524550
vis_settings += [self.invert]
525551

@@ -528,11 +554,6 @@ def visible_settings(self):
528554
if self.do_3D.value:
529555
vis_settings.remove(self.stitch_threshold)
530556

531-
if self.save_probabilities.value:
532-
vis_settings += [self.probabilities_name]
533-
if self.docker_or_python.value == 'Python':
534-
vis_settings += [self.probability_rescale_setting]
535-
536557
vis_settings += [self.use_averaging, self.use_gpu]
537558

538559
if self.docker_or_python.value == 'Python':
@@ -542,7 +563,9 @@ def visible_settings(self):
542563
if self.cellpose_version.value == 'v3':
543564
vis_settings += [self.denoise]
544565
if self.denoise.value:
545-
vis_settings += [self.denoise_type]
566+
vis_settings += [self.denoise_type, self.denoise_image]
567+
if self.denoise_image.value:
568+
vis_settings += [self.denoise_name]
546569

547570
return vis_settings
548571

@@ -876,8 +899,6 @@ def run(self, workspace):
876899
cellpose_output = numpy.load(os.path.join(temp_img_dir, unique_name + "_seg.npy"), allow_pickle=True).item()
877900
y_data = cellpose_output["masks"]
878901
flows = cellpose_output["flows"]
879-
if self.denoise.value:
880-
img_restore = cellpose_output["restore"] #TODO don't think this is correct for retrieving image for plotting
881902
finally:
882903
# Delete the temporary files
883904
try:
@@ -896,11 +917,11 @@ def run(self, workspace):
896917

897918
if self.denoise.value and self.show_window:
898919
# Need to remove unnecessary extra axes
899-
denoised_image = numpy.squeeze(img_restore)
920+
denoised_image = numpy.squeeze(input_data)
900921
if "upsample" in self.denoise_type.value:
901922
denoised_image = skimage.transform.resize(
902923
denoised_image, x_data.shape)
903-
workspace.display_data.recon = denoised_image
924+
workspace.display_data.denoised_image = denoised_image
904925

905926
if self.save_probabilities.value:
906927
if self.docker_or_python.value == "Docker":
@@ -1025,7 +1046,7 @@ def display(self, workspace, figure):
10251046
if self.denoise.value:
10261047
figure.subplot_imshow(
10271048
colormap="gray",
1028-
image=workspace.display_data.recon,
1049+
image=workspace.display_data.denoised_image,
10291050
sharexy=figure.subplot(0, 0),
10301051
title=self.denoise.value,
10311052
x=2,

0 commit comments

Comments
 (0)