fix: state whether the second channel is labels instead of guessing - #108
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
`apply_tio` dispatched on `img.shape[0] == 2` alone. The totalspineseg "step 2" layout really does carry an odd-disc segmentation there, but a genuine two-modality input -- T1+T2, in-phase/out-of-phase -- has the same shape, and it was registered as a `tio.LabelMap`: resampled nearest-neighbour, and skipped by every intensity artifact, so the two modalities came out of the pipeline differing in both respects. Channel count cannot tell those apart, so `second_channel_is_labels` says which it is, threaded through `apply_enabled` to `ArtifactTransform` and `SpatialCustomTransform` where a config can set it. It defaults to True, so the step 2 pipeline is unchanged; the existing test that pins that behaviour still passes untouched. all_augmentations.json is regenerated for the new parameter. 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 totalspineseg "step 2" layout really does carry an odd-disc segmentation in channel 1. But a genuine two-modality input — T1+T2, in-phase/out-of-phase — has exactly the same shape, and got its second modality registered as a
tio.LabelMap. torchio then resamples it nearest-neighbour and skips every intensity artifact on it, so the two modalities diverge in both interpolation and augmentation while the caller believes both were augmented together.Channel count cannot distinguish the two cases; nothing in the tensor can.
The fix
second_channel_is_labels, threaded fromArtifactTransform/SpatialCustomTransformthroughapply_enabledintoapply_tio, where a config can set it.It defaults to
True— the long-standing behaviour — so the step 2 pipeline is unchanged andtest_the_second_channel_is_treated_as_labelspasses untouched. A multi-modality caller now has a way to say so, which was previously impossible to express.all_augmentations.jsonis regenerated for the new parameter.Tests
Added to
unit_tests/test_torchio_ops.py: the default still treats channel 1 as labels;second_channel_is_labels=Falselets an intensity artifact reach it (the case that used to be inexpressible); the default leaves it alone under the same call, as the control; and a single-channel image is unaffected either way.Verified failing before the fix (3 failed) and passing after. Full suite unchanged against baseline;
ruff check .clean.🤖 Generated with Claude Code