spatialdata icon indicating copy to clipboard operation
spatialdata copied to clipboard

Account for the padding shift during vectorization + use multipolygon

Open quentinblampey opened this issue 8 months ago • 1 comments

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.

quentinblampey avatar Apr 02 '25 13:04 quentinblampey

Codecov Report

:x: Patch coverage is 88.88889% with 1 line in your changes missing coverage. Please review. :white_check_mark: Project coverage is 92.09%. Comparing base (eb5a202) to head (ae6e571). :warning: Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
src/spatialdata/_core/operations/vectorize.py 88.88% 1 Missing :warning:
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%) :arrow_down:
:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov[bot] avatar Apr 02 '25 13:04 codecov[bot]

Thanks for the PR! I leave my review.

LucaMarconato avatar May 05 '25 22:05 LucaMarconato

If you agree on my changes we can merge.

LucaMarconato avatar May 05 '25 22:05 LucaMarconato

Thanks @LucaMarconato, your change looks good!

quentinblampey avatar May 12 '25 07:05 quentinblampey