Skip to content

Fix Normalize ignoring a single explicit in_min/in_max bound - #1512

Open
eminesu wants to merge 1 commit into
TorchIO-project:mainfrom
eminesu:fix-normalize-partial-bounds
Open

eminesu wants to merge 1 commit into
TorchIO-project:mainfrom
eminesu:fix-normalize-partial-bounds

Conversation

@eminesu

@eminesu eminesu commented Sep 16, 2026

Copy link
Copy Markdown

Summary

Normalize ignores an explicitly supplied in_min when in_max is None, and vice versa — the explicit value is silently discarded and both bounds are computed from the data percentiles instead. This happens because make_params only uses the explicit bounds when both are provided.

This PR resolves each input bound independently: an explicitly supplied bound is always honored, and only the missing one is computed from the percentiles. Behaviour when both bounds are given, or when both are None, is unchanged.

Reproduction (before this PR)

import torch
import torchio as tio

image = tio.ScalarImage(torch.tensor([0., 50., 100.]).reshape(1, 1, 1, 3))
print(tio.Normalize(out_min=0., out_max=1., in_min=50.)(image).data.flatten().tolist())
# before: [0.0, 0.5, 1.0]   (in_min=50 ignored)
# after:  [0.0, 0.0, 1.0]

Changes

  • Normalize.make_params: resolve in_min / in_max independently and override the auto-computed bound(s) with any explicit value.
  • Add regression tests for the in_min-only and in_max-only cases.

Fixes #1509

Resolve each input bound independently in Normalize.make_params so an
explicitly supplied in_min or in_max is honored even when the other bound
is left to be computed from the data percentiles. Previously the explicit
value was silently discarded unless both bounds were given.

Add regression tests for the in_min-only and in_max-only cases.

Fixes TorchIO-project#1509
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