Skip to content

Fix PyQtGraph shape mismatch exception by passing levels synchronously#1477

Open
wong-ziyi wants to merge 1 commit into
MouseLand:mainfrom
wong-ziyi:fix-gui-pyqtgraph-shape-mismatch
Open

Fix PyQtGraph shape mismatch exception by passing levels synchronously#1477
wong-ziyi wants to merge 1 commit into
MouseLand:mainfrom
wong-ziyi:fix-gui-pyqtgraph-shape-mismatch

Conversation

@wong-ziyi

Copy link
Copy Markdown

Description

When a user switches color views (e.g. from rgb to gray) while rendering a 3D image, the dimensionality of the array sent to pyqtgraph ImageItem can change. In gui.py's update_plot function, self.img.setImage is called without the levels keyword argument, and then self.img.setLevels(levels) is called sequentially.

However, pyqtgraph asynchronously processes setImage by invoking makeARGB with the cached self.levels from the previous image. If the new image has a different shape but pyqtgraph tries to unpack it using the older multi-channel levels buffer, it triggers internal exceptions such as ValueError: too many values to unpack (expected 2) or Exception: levels must have shape (data.shape[-1], 2), causing the GUI rendering to abort or crash entirely.

Solution

This PR modifies update_plot in cellpose/gui/gui.py to synchronously supply the levels arguments directly into the setImage function parameters, which prevents asynchronous rendering mismatches. This matches best-practice guidelines for pyqtgraph.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant