fix: deform the SynthSeg label map before cropping it - #110
Open
Hendrik-code wants to merge 1 commit into
Open
Hendrik-code wants to merge 1 commit into
Hendrik-code wants to merge 1 commit into
Conversation
The module docstring states the order as "spatial deform -> [optional random
crop] -> flip", and lab2im's RandomSpatialDeformation(output_shape=...)
resamples the full label map onto the output grid. The code cropped first.
That is not a stale comment. `warp_volume` pads with zeros, so deforming an
already-cropped box pulls background in from immediately outside it, where the
reference pulls in the real anatomy that sits there. Measured over 40 seeds on a
fully labelled 24-cube cropped to 16 -- every background voxel in the output is
therefore invented padding:
crop -> deform: mean 13.5% background, 0/40 draws with none
deform -> crop: mean 3.3% background, 7/40 draws with none
Deforming first does not remove the effect entirely (a crop landing against the
volume edge still meets padding), but it is the order the reference uses and it
cuts the imported background fourfold.
No shipped config changes: `output_shape` defaults to None and is not among
RandomSynthSegGPU's accepted parameters, so the crop only runs for a caller
constructing SynthSegGenerator directly. Both facts are asserted in the test
rather than left as a claim.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
The defect
The module docstring states the order as
and lab2im's
RandomSpatialDeformation(output_shape=...)resamples the full label map onto the output grid. The code ran_random_cropfirst and the warp second.That is a real behavioural divergence, not a stale comment:
warp_volumeusespadding_mode="zeros", so deforming a box that has already been cropped pulls background in from immediately outside it — where the reference implementation pulls in the real anatomy that sits there.Measured
40 seeds, a fully labelled 24-cube input (no background anywhere) cropped to 16, so every background voxel in the output is invented padding:
Deforming first does not remove the effect entirely — a crop landing against the volume edge still meets padding — but it is the order the reference uses and it cuts the imported background roughly fourfold. The PR does not claim more than that.
Behaviour change: none for any shipped config
output_shapedefaults toNone, and it is not amongRandomSynthSegGPU's accepted parameters, so the crop only ever runs for a caller constructingSynthSegGeneratordirectly. Both facts are asserted in the test rather than left as a claim.Tests
unit_tests/test_synthseg_crop_order.py: the output still has the requested shape; the measured background thresholds sit between the two orders, so the test fails on the old one; the source order matches the docstring; and the two "unreachable from a config" facts are pinned.Verified failing before the fix (2 failed) and passing after. Full suite unchanged against baseline;
ruff check .clean.🤖 Generated with Claude Code