Repository navigation
Preserve contour holes before dissolving chunked label polygons - #1299
Open
sophiamaedler wants to merge 2 commits into
Open
sophiamaedler wants to merge 2 commits into
sophiamaedler wants to merge 2 commits into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1299 +/- ##
==========================================
+ Coverage 91.43% 91.45% +0.01%
==========================================
Files 53 53
Lines 8395 8400 +5
==========================================
+ Hits 7676 7682 +6
+ Misses 719 718 -1
🚀 New features to boost your workflow:
|
This branch has not been deployed
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.
fixes #1235
_region_props_to_polygoncurrently converts each contour into a separate polygon, so an interior contour becomes a filled shell rather than a hole. This produces invalidMultiPolygons with nested shells.When a label spans multiple chunks, the subsequent dissolve can fill that incorrectly represented hole and return a valid but incorrect polygon. If another label occupies the hole, the resulting shapes overlap despite the raster labels being mutually exclusive. These overlaps can cause downstream area calculations to double-count regions.
This change applies
make_validto invalid geometries with multiple contour rings before chunk fragments are dissolved. Single-ring geometries skip the additional validity check. Regression tests cover occupied holes with different chunk sizes and preservation of disconnected components.Benchmark results
The benchmark uses the complete
cell_labelslayer from the public 10x Xenium human lung cancer SpatialData object, distributed asxenium_2.0.0_io_spatialdata_0.7.1.zipon the SpatialData dataset page.The raster contains 17,098 × 51,187 pixels and 162,254 cell labels. It was loaded into memory once and divided into 1024 × 1024 chunks. Each implementation ran once using Dask's single-threaded scheduler. Data loading and geometry validation were excluded from the timings.
Cell IDs were unchanged. The measured runtime difference was +0.64%. These are single-run wall times. Invalid baseline geometries were counted separately and excluded from intersection calculations.
All 22 vectorization tests passed, along with Ruff and mypy checks.
Download the dataset and run the benchmark
From this PR's checkout, using Python 3.12 or later:
Save the script benchmark_xenium_vectorization.py as
temp/xenium-vectorization/benchmark_xenium_vectorization.py, then run:Images, transcripts and tables are not needed for this benchmark.