Skip to content

Fix Normalize when only one input bound is provided - #1510

Open
afei615 wants to merge 2 commits into
TorchIO-project:mainfrom
afei615:codex/1509-normalize-single-bound
Open

afei615 wants to merge 2 commits into
TorchIO-project:mainfrom
afei615:codex/1509-normalize-single-bound

Conversation

@afei615

@afei615 afei615 commented Sep 9, 2026

Copy link
Copy Markdown

Fixes #1509.

Description

When only in_min or in_max is specified, Normalize currently discards it and infers both bounds. Sample each explicit bound once and combine it with the per-image percentile range so the supplied endpoint is retained.

The six original regression cases cover either endpoint, Choice inputs, masked percentiles for multiple images, and inverse restoration of clipped values. They fail on the unchanged base.

Additional parameterized checks cover 96 combinations of bound modes, dtypes, 2D/3D multichannel shapes, masks, and subject/batch inputs against an independent NumPy reference; 18 random-bound cases; four empty-mask/zero-range cases; and six CPU/CUDA comparisons. Of these 124 additional cases, 70 fail and 54 pass on the unchanged base. All 163 tests (130 added and 33 existing) pass with this change, including the six CUDA cases on the local GPU.

Validation

  • python -m pytest tests/test_normalize.py -q — 163 passed.
  • ruff check src/torchio/transforms/intensity/normalize.py tests/test_normalize.py — passed.
  • ruff format --check src/torchio/transforms/intensity/normalize.py tests/test_normalize.py — passed.
  • ty check src/torchio/transforms/intensity/normalize.py tests/test_normalize.py — passed.
  • Windows, Python 3.10.18, PyTorch 2.0.1+cu117, CPU and CUDA tensors. Full CI matrix has not been run locally. These are synthetic-input contract tests, not validation on clinical datasets.

Checklist

  • I have read the CONTRIBUTING docs and have a developer setup ready.
  • Non-breaking bug fix to match the documented input-bound behavior.
  • Tests added to cover the change.
  • In-line docstrings updated (existing parameter documentation already describes this behavior).
  • Documentation updated (not required for the existing contract).
  • This pull request is ready to be reviewed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Normalize silently ignores in_min or in_max when only one is provided

1 participant