Skip to content

Fix: Resolve negative seg_level before passing to OpenSlide#321

Open
ItzDEXX wants to merge 1 commit intomahmoodlab:masterfrom
ItzDEXX:fix-negative-seg-level
Open

Fix: Resolve negative seg_level before passing to OpenSlide#321
ItzDEXX wants to merge 1 commit intomahmoodlab:masterfrom
ItzDEXX:fix-negative-seg-level

Conversation

@ItzDEXX
Copy link

@ItzDEXX ItzDEXX commented Jan 23, 2026

Problem

OpenSlide's C library doesn't support Python's negative indexing. When seg_level=-1 is passed, read_region returns a black image, causing findContours to return zero contours and hierarchy=None, which crashes at np.squeeze().

Fix

This fix converts negative seg_level to the appropriate positive level using get_best_level_for_downsample(64) before any OpenSlide calls.

OpenSlide's C library doesn't support Python's negative indexing.
When seg_level=-1 is passed, read_region returns a black image,
causing findContours to return zero contours and hierarchy=None,
which crashes at np.squeeze().
This fix converts negative seg_level to the appropriate positive
level using get_best_level_for_downsample(64) before any OpenSlide calls.
@ItzDEXX
Copy link
Author

ItzDEXX commented Jan 24, 2026

@guillaumejaume @faisalml It would be great if you look into this

@ItzDEXX
Copy link
Author

ItzDEXX commented Jan 26, 2026

Can someone take a look at this ?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant