Repository navigation
Fix: labels_to_shapes never drops a label that simplification collapses (F14) - #43
Merged
Merged
Conversation
…ollapses (F14) A ring that simplification would leave with fewer than 3 vertices keeps its un-simplified outline. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Y2SN8SuEakTdiWy3F2WUqN
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.
With the default
simplify=0.5, objects whose outline collapsed under simplification (a single pixel, 1x3 bars atsimplify=1.0) were silently dropped, solabels_to_shapesreturned[]for an image of single-pixel objects.Now every label with at least
min_areapixels gets exactly one feature. In_rings_of, a ring whose simplified version has fewer than 4 points keeps its un-simplified contour; this is per ring, so a collapsed hole stays a hole. If a label somehow has no polygon,labels_to_shapesraisesToolError("bad_return", ...)instead of skipping it (unreachable today; a safety net against silent drops).One deviation from the brief, for your decision: a single pixel is a 4-vertex diamond (vertices
(x, y±0.5)and(x±0.5, y), area 0.5), not a unit square, becausefind_contoursat level 0.5 always cuts convex corners. That is already whatsimplify=0produced, so one image can mix cut-corner and pixel-corner outlines. Documented in the docstring. Exact unit squares would mean changing the ring tracing for every outline (coordinates would change for all users), so it is not done here.Docs:
MANIFEST.md(ShapesOut row) andREGRESSION_LEDGER.md. Newtests/test_shapes_every_label.py(5 tests: a Hypothesis property oversimplifyin {0, 0.5, 1, 3} andmin_area1..6 that every label with at leastmin_areapixels appears exactly once with the rightareaand closed rings; unsimplified area within the corner-cut tolerance and the outline rasterises back to the mask exactly; the single-pixel diamond; 25 single-pixel labels; a collapsed hole is kept). F14 is removed from the known failures, so the matrix caseoutline_labels/single-pixel-default-simplifynow runs. No existing test edited (aknown_failuredecorator and its now-unused import were removed from one test).Host checks to do in the host-parity work: QuPath: a diamond has JTS area 0.5 while the
areaproperty says 1 (read the property for pixel counts); Fiji: drop the closing duplicate vertex before building thePolygonRoi; Napari: a shapes layer takes a 4-vertex polygon; all hosts: images with many tiny objects now produce one feature per label, so apply the 50 000 cap and "left out" message the same way everywhere. Separate docs note:docs/HOST_FEATURES.mdline 30 ("Not yet in any host: shapes outputs, ...") contradicts line 25 and is stale; it goes to the documentation audit.Verified by the author on Linux, Python 3.11: black, ruff, mypy; the full suite has only the two environmental sandbox failures; I re-ran lint and the shapes, geometry, known-failure and
test_shapessuites (48 tests OK) and checked the single-pixel output. Not verified: coverage floor (CI runs it), Windows, macOS.🤖 Generated with Claude Code
https://claude.ai/code/session_01Y2SN8SuEakTdiWy3F2WUqN
Generated by Claude Code