Repository navigation
Refuse negative mask labels (background was counted as an object) - #40
Merged
Merged
Conversation
…object A signed mask holding a negative value made piece_counts keep 0 as a label (0 was dropped only when it was the smallest value), so the background became an object and the mask kinds, counts and mask_relationships.json were wrong with no warning. Label 0 is the background and objects are positive (contract §15): read_mask, piece_counts and pair_counts now raise ValueError for negative labels, and the masks command prints the message and exits 1 without writing a report. Fixes #35 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Scma6W3LC11s3qjXHZuGDm
This was referenced Oct 29, 2026
…labels # Conflicts: # src/morphobricks_preprocessing/mask_scan.py # src/morphobricks_preprocessing/masks.py # tests/test_mask_scan.py # tests/test_masks.py
Contributor
Author
|
Merged main (#42, #43) in: Generated by Claude Code |
This was referenced Oct 30, 2026
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.
Summary
Fixes #35.
check_labels(pixels, name)raisesValueErrorwhen a mask holds a negative value;read_maskcalls it.piece_countsandpair_countscall it too, so 0 is always the background (it can only be dropped as "the smallest value" once negatives are refused).maskscommand catches theValueErrorfromscan_masks, prints it with the mask's path and exits 1. No report is written.Why
At v0.3.1, if an int16 mask held -1, 0 and 3,
piece_countsreturned the labels[-1, 0, 3]. That made the background an object, and the mask kinds, object counts andmask_relationships.jsoncame out wrong with no warning. The header check cannot see pixel values, so a signed dtype is still accepted there. The refusal happens when the pixels are read. This follows the existing rule that a mask which is not 2D when read raises an error.Notes for review
ValueError, not aValidationIssue, because the header-onlyfind_masksnever reads pixels.Tests
tests/test_mask_scan.py::test_negative_labels_are_refused_never_read_as_objectstests/test_masks.py::test_masks_command_refuses_negative_labelspiece_countsof the -1/0/3 mask returns[-1, 0, 3].test_discovery.py:472: running as root ignores file modes. On main the same environment gives 1051 passed, 1 skipped.ruff check .andruff format --check .are clean.Generated by Claude Code