Skip to content

Commit 74b6ba0

Browse files
committed
fix layer_ortho index error due to size mismatch on dropping image when image already loaded in 3D GUI
- refactor ortho outpix calculation - add update function where needed - move crosshair update to before getting locations to fix IndexError on previous image size
1 parent 68161d1 commit 74b6ba0

3 files changed

Lines changed: 21 additions & 15 deletions

File tree

cellpose/gui/gui.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,6 +1116,8 @@ def remove_single_cell(self, idx):
11161116
self.cellpix[self.cellpix > idx] -= 1
11171117
self.outpix[self.outpix > idx] -= 1
11181118

1119+
self.update_outpix_ortho()
1120+
11191121
if self.NZ == 1:
11201122
self.removed_cell = [
11211123
self.ismanual[idx - 1], self.cellcolors[idx],
@@ -1485,12 +1487,26 @@ def draw_mask(self, z, ar, ac, vr, vc, color, idx=None):
14851487
self.cellpix[z, ar, ac] = idx
14861488
self.outpix[z, vr, vc] = idx
14871489

1490+
self.update_ortho_outpix()
1491+
14881492
if z == self.currentZ:
14891493
self.layerz[ar, ac, :3] = color
14901494
if self.masksOn:
14911495
self.layerz[ar, ac, -1] = self.opacity
14921496
if self.outlinesOn:
14931497
self.layerz[vr, vc] = np.array(self.outcolor)
1498+
1499+
def update_ortho_outpix(self):
1500+
if self.NZ == 1:
1501+
return
1502+
1503+
# calculate ZY and ZX outlines:
1504+
outlines_YZ = masks_to_outlines(self.cellpix.transpose(1, 2, 0))
1505+
self.outpix_YZ = outlines_YZ * self.cellpix.transpose(1, 2, 0)
1506+
1507+
outlines_ZX = masks_to_outlines(self.cellpix.transpose(2, 1, 0))
1508+
self.outpix_ZX = outlines_ZX * self.cellpix.transpose(2, 1, 0)
1509+
14941510

14951511
def compute_scale(self):
14961512
# get diameter from gui

cellpose/gui/gui3d.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ def add_orthoviews(self):
376376
self.yortho = self.Ly // 2
377377
self.xortho = self.Lx // 2
378378
if self.NZ > 1:
379+
self.update_ortho_outpix()
379380
self.update_ortho()
380381

381382
self.win.addItem(self.pOrtho[0], 0, 1, rowspan=1, colspan=1)
@@ -429,8 +430,6 @@ def update_ortho(self):
429430
self.pOrtho[0].setXRange(-self.dz / 3, self.dz * 2 + self.dz / 3)
430431
self.pOrtho[1].setYRange(-self.dz / 3, self.dz * 2 + self.dz / 3)
431432
dztot = min(self.NZ, self.dz * 2)
432-
y = self.yortho
433-
x = self.xortho
434433
z = self.currentZ
435434
if dztot == self.NZ:
436435
zmin, zmax = 0, self.NZ
@@ -445,6 +444,8 @@ def update_ortho(self):
445444
zmin, zmax = z - self.dz, z + self.dz
446445
self.zc = z - zmin
447446
self.update_crosshairs()
447+
y = self.yortho
448+
x = self.xortho
448449
if self.view == 0 or self.view == 4:
449450
for j in range(2):
450451
if j == 0:
@@ -578,6 +579,7 @@ def plot_clicked(self, event):
578579
def update_plot(self):
579580
super().update_plot()
580581
if self.NZ > 1 and self.orthobtn.isChecked():
582+
self.update_ortho_outpix()
581583
self.update_ortho()
582584
self.win.show()
583585
self.show()

cellpose/gui/io.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -429,22 +429,10 @@ def _masks_to_gui(parent, masks, outlines=None, colors=None):
429429
outlines = masks_to_outlines(parent.cellpix)
430430
parent.outpix = outlines * parent.cellpix
431431

432-
# calculate ZY and ZX outlines:
433-
outlines_YZ = masks_to_outlines(parent.cellpix.transpose(1, 2, 0))
434-
parent.outpix_YZ = outlines_YZ * parent.cellpix.transpose(1, 2, 0)
435-
436-
outlines_ZX = masks_to_outlines(parent.cellpix.transpose(2, 1, 0))
437-
parent.outpix_ZX = outlines_ZX * parent.cellpix.transpose(2, 1, 0)
438-
439432
else:
440433
parent.outpix = outlines # set YX outlines
441434

442-
# calculate ZY and ZX outlines:
443-
outlines_YZ = masks_to_outlines(parent.cellpix.transpose(1, 2, 0))
444-
parent.outpix_YZ = outlines_YZ * parent.cellpix.transpose(1, 2, 0)
445-
446-
outlines_ZX = masks_to_outlines(parent.cellpix.transpose(2, 1, 0))
447-
parent.outpix_ZX = outlines_ZX * parent.cellpix.transpose(2, 1, 0)
435+
parent.update_ortho_outpix()
448436

449437
if parent.outpix.ndim == 2:
450438
parent.outpix = parent.outpix[np.newaxis, :, :]

0 commit comments

Comments
 (0)