From 7a1f109e4741816961cb9a44bd8c2b044c43a7b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20P=C3=A9rez-Garc=C3=ADa?= Date: Tue, 24 Oct 2023 19:26:59 +0100 Subject: [PATCH] Add failing test --- tests/transforms/preprocessing/test_rescale.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/transforms/preprocessing/test_rescale.py b/tests/transforms/preprocessing/test_rescale.py index 9fb1da87..8cb00485 100644 --- a/tests/transforms/preprocessing/test_rescale.py +++ b/tests/transforms/preprocessing/test_rescale.py @@ -119,3 +119,18 @@ def test_invert_rescaling(self): assert transformed.t1.data.max() == 1 inverted = transformed.apply_inverse_transform() self.assert_tensor_almost_equal(inverted.t1.data, data) + + def test_persistent_in_min_max(self): + # see https://github.com/fepegar/torchio/issues/1115 + img1 = torch.tensor([[[[0, 1]]]]) + img2 = torch.tensor([[[[0, 10]]]]) + + rescale = tio.RescaleIntensity(out_min_max=(0, 1)) + + assert rescale(img1).data.flatten().tolist() == [0, 1] + assert rescale(img2).data.flatten().tolist() == [0, 1] + + rescale = tio.RescaleIntensity(out_min_max=(0, 1)) + + assert rescale(img2).data.flatten().tolist() == [0, 1] + assert rescale(img1).data.flatten().tolist() == [0, 1]