Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEATURE: ctrl-c/v to copy the selected mask into the current layer #1019

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions cellpose/gui/gui3d.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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:
Expand Down
10 changes: 9 additions & 1 deletion cellpose/gui/guihelpwindowtext.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@
<td>CTRL+Z</td>
<td>undo previously drawn mask/stroke</td>
</tr>
<tr>
<td>CTRL+C</td>
<td>(3D only) Copy the selected mask into the current layer, using the nearest containing layer
(preferring previous layers to later)</td>
</tr>
<tr>
<td>CTRL+V</td>
<td>(3D only) As CTRL+C, but preferring subsequent layers to previous ones.</td>
<tr>
<td>CTRL+Y</td>
<td>undo remove mask</td>
Expand Down Expand Up @@ -105,7 +113,7 @@
</tr>
<tr>
<td>A/D or LEFT/RIGHT</td>
<td>cycle through images in current directory</td>
<td>cycle through images in current directory/Z-stack</td>
</tr>
<tr>
<td>W/S or UP/DOWN</td>
Expand Down
6 changes: 3 additions & 3 deletions cellpose/gui/guitrainhelpwindowtext.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<li>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.
</li>
<li>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.
<li>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.
</li>
<li> Go to the "Models" menu in the File bar at the top and click "Train new model..." or use shortcut CTRL+T.
</li>
Expand Down