From a9f204268d5047578a368dad8b7b436e537cdefa Mon Sep 17 00:00:00 2001 From: Martin Chase Date: Tue, 24 Sep 2024 11:00:42 -0700 Subject: [PATCH] add ctrl-c/v to copy the selected mask into the current layer --- cellpose/gui/gui3d.py | 24 ++++++++++++++++++++++++ cellpose/gui/guihelpwindowtext.html | 10 +++++++++- cellpose/gui/guitrainhelpwindowtext.html | 6 +++--- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/cellpose/gui/gui3d.py b/cellpose/gui/gui3d.py index 8a3f9eea..ecb94751 100644 --- a/cellpose/gui/gui3d.py +++ b/cellpose/gui/gui3d.py @@ -1,6 +1,7 @@ """ Copyright © 2023 Howard Hughes Medical Institute, Authored by Carsen Stringer and Marius Pachitariu. """ +from itertools import zip_longest import sys, os, pathlib, warnings, datetime, time @@ -629,6 +630,29 @@ def keyPressEvent(self, event): if event.key() == QtCore.Qt.Key_Minus or event.key() == QtCore.Qt.Key_Equal: self.p0.keyPressEvent(event) + if event.modifiers() & QtCore.Qt.ControlModifier and self.selected > 0: + if event.key() == QtCore.Qt.Key_V: + self._copySelectedMaskIntoLayer(previous=False) + elif event.key() == QtCore.Qt.Key_C: + self._copySelectedMaskIntoLayer(previous=True) + + self.update_plot() + self.draw_layer() + self.update_layer() + + def _copySelectedMaskIntoLayer(self, previous: bool): + first = tuple(range(self.currentZ + 1, self.NZ)) + second = tuple(range(self.currentZ - 1, -1, -1)) + if previous: + first, second = second, first + zipped = zip_longest(first, second, fillvalue=None) + search = [item for sublist in zipped for item in sublist if item is not None] + for z in search: + selected = self.cellpix[z] == self.selected + if np.any(selected): + self.cellpix[self.currentZ][selected] = self.selected + break + def update_ztext(self): zpos = self.currentZ try: diff --git a/cellpose/gui/guihelpwindowtext.html b/cellpose/gui/guihelpwindowtext.html index 4ca5d209..e5550efd 100644 --- a/cellpose/gui/guihelpwindowtext.html +++ b/cellpose/gui/guihelpwindowtext.html @@ -63,6 +63,14 @@ CTRL+Z undo previously drawn mask/stroke + + CTRL+C + (3D only) Copy the selected mask into the current layer, using the nearest containing layer + (preferring previous layers to later) + + + CTRL+V + (3D only) As CTRL+C, but preferring subsequent layers to previous ones. CTRL+Y undo remove mask @@ -105,7 +113,7 @@ A/D or LEFT/RIGHT - cycle through images in current directory + cycle through images in current directory/Z-stack W/S or UP/DOWN diff --git a/cellpose/gui/guitrainhelpwindowtext.html b/cellpose/gui/guitrainhelpwindowtext.html index f1983591..5359a978 100644 --- a/cellpose/gui/guitrainhelpwindowtext.html +++ b/cellpose/gui/guitrainhelpwindowtext.html @@ -5,9 +5,9 @@
  • Run the built-in models on one of the images using the "model zoo" and find the one that works best for your data. Make sure that if you have a nuclear channel you have selected it for CHAN2.
  • -
  • Fix the labelling by drawing new ROIs (right-click) and deleting incorrect ones (CTRL+click). The GUI - autosaves any manual changes (but does not autosave after running the model, for that click CTRL+S). The - segmentation is saved in a "_seg.npy" file. +
  • Fix the labelling by drawing new ROIs (right-click) and deleting incorrect ones (CTRL+click). See general + GUI Help page for more keybindings. The GUI autosaves any manual changes (but does not autosave after + running the model, for that click CTRL+S). The segmentation is saved in a "_seg.npy" file.
  • Go to the "Models" menu in the File bar at the top and click "Train new model..." or use shortcut CTRL+T.