Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1267 +/- ##
=======================================
Coverage 91.40% 91.40%
=======================================
Files 53 53
Lines 8381 8381
=======================================
Hits 7661 7661
Misses 720 720
🚀 New features to boost your workflow:
|
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.
Closes #1202
Hello there. Thanks for the clear report and the reproduction script, they made this easy to track down. I can confirm the bug on current
main: starting from a mask that contains only the ids 0, 1 and 50, rotating the multiscale labels by 30° gave 44 distinct ids atscale0and 33 atscale1, andScale(1.5)produced id 17. Single-scale labels were correct.Cause
Segmentation labels are categorical data: each value names an instance rather than measuring an intensity, so there is no meaningful value between cell 1 and cell 50. Linear interpolation suits intensities, but on labels it produces weighted averages of neighbouring ids along every boundary. These either match no row of the annotating table, or coincide with the id of an unrelated cell, which then silently propagates into anything computed per instance, such as aggregation or table joins. Nearest-neighbour resampling (
order=0) is the appropriate choice, since every output pixel then copies an id that exists in the input.In the
DataTreeoverload oftransform(), labels were resampled with only{"prefilter": False}, sodask_image.ndinterp.affine_transformused its defaultorder=1. TheDataArrayoverload already usesorder=0.Fix
I added
order=0for labels in theDataTreeoverload and replaced the# TODO: this should work, test bettercomment there with a short explanation.transform(sdata, ...)andtransform_to_coordinate_system()use the same overload, so they're covered too.Tests
The existing
test_transform_rastercompares extents only, so the label values weren't checked. The new tests assert that, at every resolution level, the set of ids is a subset of the input ids (nothing is invented) and still contains both cells (so the check can't pass trivially). They cover:SpatialDataobjectLabels3DModel)Without the fix, the 5 multiscale cases fail; with it, all 10 pass. The full suite goes from 1373 to 1383 passing tests, with no other changes.
Not included
The issue also notes that single-scale images are resampled with nearest neighbour, while multiscale images are linearly interpolated. Since choosing one policy for images (and possibly exposing
order) is a design decision, I left it for #725