Fix IndexError when loading image with auto-adjust saturation unchecked#1453
Open
chenyenchung wants to merge 3 commits into
Open
Fix IndexError when loading image with auto-adjust saturation unchecked#1453chenyenchung wants to merge 3 commits into
chenyenchung wants to merge 3 commits into
Conversation
8b06240 to
e95f936
Compare
mrariden
reviewed
May 19, 2026
Collaborator
mrariden
left a comment
There was a problem hiding this comment.
See if the GH tests pass, and remove the tests if they dont
| super(MainW, self).__init__() | ||
|
|
||
| self.logger = logger | ||
| self.logger = logger if logger is not None else logging.getLogger(__name__) |
Collaborator
There was a problem hiding this comment.
These tests seem a bit fragile but we can keep them if they pass the GH workflow.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1453 +/- ##
==========================================
- Coverage 41.99% 41.86% -0.13%
==========================================
Files 16 16
Lines 3777 3810 +33
==========================================
+ Hits 1586 1595 +9
- Misses 2191 2215 +24 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Dear Cellpose team,
Thank you for the great tool! Please find below a bug report and a proposed fix for saturation updates in the GUI:
In Zstack mode (
python -m cellpose --Zstack), if an image is loaded when auto-adjust saturation is unchecked, anIndexError: list index out of range is raised:This appears to be introduced in a982535 when saturation update when
parent.NZchanges was disabled. This causes self.saturation not updating its shape at loading and remaining[]or per the last image loaded when auto-adjust saturation was checked. The first timeupdate_plot()indexesself.saturation[c][self.currentZ](e.g. viamove_in_Zafter the user scrolls, or immediately during the initial render atcurrentZ = NZ // 2), the list is shorter than the newNZand indexing fails.To fix this issue, in
cellpose/gui/io.py_initialize_images, afterparent.NZis updated to the new image's Z depth, add an else branch to the existing ifparent.autobtn.isChecked():block that re-sizes self.saturation to 3 ×NZ. The user's previous per-channel values are preserved by broadcasting each channel's first-Z value across the new Z range; channels with no previous value default to [0, 255].The structure is the same 3 × NZ × 2 (channel × Z × [lo, hi]) that
compute_saturationproduces, soupdate_plot,level_change, and the ortho views can index it without further changes.A new test asserting
self.saturationis 3 × NZ after loading with auto-adjust off is also added.Please let me know if you need more information. Thank you.
Best,
Yen