Skip to content
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
4 changes: 2 additions & 2 deletions cellpose/gui/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class MainW(QMainWindow):
def __init__(self, image=None, logger=None):
super(MainW, self).__init__()

self.logger = logger
self.logger = logger if logger is not None else logging.getLogger(__name__)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

helpful, thanks

pg.setConfigOptions(imageAxisOrder="row-major")
self.setGeometry(50, 50, 1200, 1000)
self.setWindowTitle(f"cellpose v{version}")
Expand Down Expand Up @@ -2153,4 +2153,4 @@ def go_next_previous_dropdown(self, dropdown, increment=1):
return
idx += increment

self.logger.error('Could not find an emabled dropdown item.')
self.logger.error('Could not find an emabled dropdown item.')
13 changes: 12 additions & 1 deletion cellpose/gui/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,18 @@ def _initialize_images(parent, image, load_3D=False):
if parent.restore is None or parent.restore != "filter":
parent.logger.info(": normalization checked: computing saturation levels (and optionally filtered image)")
parent.compute_saturation()

else:
# auto-adjust off: re-size saturation list to match NZ while
# preserving the user's per-channel values (first-Z value is
# broadcast across the new Z range).
prev = parent.saturation if hasattr(parent, 'saturation') else []
parent.saturation = []
for r in range(3):
if r < len(prev) and len(prev[r]) > 0:
sval = prev[r][0]
else:
sval = [0, 255]
parent.saturation.append([list(sval) for n in range(parent.NZ)])
parent.compute_scale()
parent.track_changes = []

Expand Down
64 changes: 64 additions & 0 deletions tests/test_gui.py
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests seem a bit fragile but we can keep them if they pass the GH workflow.

Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import numpy as np
import pytest


@pytest.fixture(scope="module")
def qapp():
from qtpy.QtWidgets import QApplication
app = QApplication.instance() or QApplication([])
yield app


@pytest.fixture(scope="module")
def win(qapp):
from cellpose.gui.gui3d import MainW_3d
return MainW_3d()


@pytest.mark.slow
def test_saturation_invariants_with_autobtn_unchecked(win):
"""Regression: when 'auto-adjust saturation' is unchecked, loading a 3D
image must (1) leave self.saturation sized 3 x NZ so that update_plot's
self.saturation[c][currentZ] index is valid, and (2) preserve the user's
per-channel values across reloads that change NZ."""
from cellpose.gui import io as gui_io

win.autobtn.setChecked(False)

# First load: NZ=10, saturation must be 3 x 10 with valid [lo, hi] entries.
win.load_3D = True
win.filename = "test.tif"
gui_io._initialize_images(
win, np.zeros((10, 64, 64, 3), dtype=np.float32), load_3D=True
)

assert win.NZ == 10
assert len(win.saturation) == 3
for c in range(3):
assert len(win.saturation[c]) == win.NZ
for z in range(win.NZ):
assert len(win.saturation[c][z]) == 2 # [lo, hi]

# Trigger the original failure path explicitly: move_in_Z -> update_plot
# -> setLevels(self.saturation[self.color - 1][self.currentZ]).
win.loaded = True
win.color = 1 # red channel (color > 0 and < 4 branch)
win.nchan = 3
win.scroll.setValue(win.NZ - 1)
win.move_in_Z() # would have raised IndexError pre-fix

# User picks custom per-channel values.
for c in range(3):
for z in range(win.NZ):
win.saturation[c][z] = [10 + c, 200 + c]

# Reload with a different NZ; user values should be broadcast across new Z.
gui_io._initialize_images(
win, np.zeros((8, 64, 64, 3), dtype=np.float32), load_3D=True
)

assert win.NZ == 8
for c in range(3):
assert len(win.saturation[c]) == win.NZ
for z in range(win.NZ):
assert win.saturation[c][z] == [10 + c, 200 + c]
Loading