Skip to content

fix: NaN brightness features for empty masks - #84

Merged
paulmueller merged 1 commit into
DC-analysis:mainfrom
paulmueller-agent:fix-brightness-empty-mask
Nov 23, 2026
Merged

paulmueller merged 1 commit into
DC-analysis:mainfrom
paulmueller-agent:fix-brightness-empty-mask

Conversation

@paulmueller-agent

Copy link
Copy Markdown
Contributor

The numba helpers in feat_brightness/bright_all.py assumed that every mask has at least one pixel. For an empty mask, np.mean of an empty selection fails inside the njit function:

compute_avg_sd_masked_uint8(image, mask)  # mask[0] is empty
ZeroDivisionError: division by zero

compute_percentiles_10_90 fails with an IndexError for 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_label skips them), so this only affects direct use of brightness_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_int16 and compute_percentiles_10_90 return NaN for empty masks. The docstrings mention this.

Tests

  • New 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.
  • All feature tests pass (71), as do a few pipeline tests (simple, bg_off with thresh, chained).
  • flake8 is clean, and ruff shows no new errors.

🤖 Generated with Claude Code

`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
paulmueller merged commit c7a8797 into DC-analysis:main Nov 23, 2026
6 checks passed
@codecov

codecov Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.19%. Comparing base (6dbc20d) to head (fcc4f55).
⚠️ Report is 2 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

2 participants