Skip to content

Account for the padding shift during vectorization + use multipolygon#921

Merged
melonora merged 6 commits intoscverse:mainfrom
quentinblampey:fix_vectorize
May 27, 2025
Merged

Account for the padding shift during vectorization + use multipolygon#921
melonora merged 6 commits intoscverse:mainfrom
quentinblampey:fix_vectorize

Conversation

@quentinblampey
Copy link
Copy Markdown
Contributor

In _vectorize_mask, we pad the mask before using find_contours, which is needed to have correct geometries. Yet, it create a shift of one pixel in the coordinates.

This PR shifts the geometry of one pixel to recover the original coordinates. In the test that I added, when doing rasterize + vectorize, we now have an IoU of 0.98 instead of 0.92.

When one label has multiple geometries, I now use a MultiPolygon instead of multiple Polygon. This is more convenient and less ambiguous, as we'll have only one row per label from the mask.

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 2, 2025

Codecov Report

❌ Patch coverage is 88.88889% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 92.09%. Comparing base (eb5a202) to head (ae6e571).
⚠️ Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
src/spatialdata/_core/operations/vectorize.py 88.88% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #921      +/-   ##
==========================================
- Coverage   92.11%   92.09%   -0.02%     
==========================================
  Files          48       48              
  Lines        7429     7430       +1     
==========================================
  Hits         6843     6843              
- Misses        586      587       +1     
Files with missing lines Coverage Δ
src/spatialdata/_core/operations/vectorize.py 93.12% <88.88%> (-0.59%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@LucaMarconato
Copy link
Copy Markdown
Member

Thanks for the PR! I leave my review.

@LucaMarconato
Copy link
Copy Markdown
Member

If you agree on my changes we can merge.

@quentinblampey
Copy link
Copy Markdown
Contributor Author

Thanks @LucaMarconato, your change looks good!

@melonora melonora merged commit 60be9ce into scverse:main May 27, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants