Repository navigation
fix: NaN brightness features for empty masks - #84
Merged
paulmueller merged 1 commit intoNov 23, 2026
Merged
Conversation
`compute_avg_sd_masked_uint8`, `compute_avg_sd_masked_int16`, and `compute_percentiles_10_90` failed with a `ZeroDivisionError` (or an `IndexError`) for an empty mask, so `brightness_features` could not be computed for the other masks either. Features that cannot be computed are NaN now, as for the other feature functions. Note that the pipeline never passes empty masks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
paulmueller
approved these changes
Nov 23, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #84 +/- ##
==========================================
- Coverage 88.21% 88.19% -0.03%
==========================================
Files 63 63
Lines 4530 4539 +9
==========================================
+ Hits 3996 4003 +7
- Misses 534 536 +2 ☔ View full report in Codecov by Harness. 🚀 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.
The numba helpers in
feat_brightness/bright_all.pyassumed that every mask has at least one pixel. For an empty mask,np.meanof an empty selection fails inside the njit function:compute_percentiles_10_90fails with anIndexErrorfor the same reason. Because the helpers process all masks in one call, one empty mask meant that no brightness features could be computed for any mask.The pipeline itself never passes empty masks (
get_masks_from_labelskips them), so this only affects direct use ofbrightness_features. As agreed for feature extraction, features that cannot be computed should be NaN rather than raising.Fix
compute_avg_sd_masked_uint8,compute_avg_sd_masked_int16andcompute_percentiles_10_90return NaN for empty masks. The docstrings mention this.Tests
test_brightness_empty_mask: an empty mask and a 4×4 mask. The features of the empty mask are NaN, and those of the other mask are correct. It fails on main and passes here.🤖 Generated with Claude Code