Skip to content

Commit acfc508

Browse files
authored
Fix dtype bug in ScaleIntensityRangePercentile (#8109)
Fixes #8108 ### Types of changes <!--- Put an `x` in all the boxes that apply, and remove the not applicable items --> - [x] Non-breaking change (fix or new feature that would not break existing functionality). - [ ] Breaking change (fix or new feature that would cause existing functionality to change). - [ ] New tests added to cover the changes. - [ ] Integration tests passed locally by running `./runtests.sh -f -u --net --coverage`. - [ ] Quick tests passed locally by running `./runtests.sh --quick --unittests --disttests`. - [ ] In-line docstrings updated. - [ ] Documentation updated, tested `make html` command in the `docs/` folder. --------- Signed-off-by: YunLiu <[email protected]>
1 parent fa1c1af commit acfc508

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

monai/transforms/intensity/array.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1411,7 +1411,7 @@ def __call__(self, img: NdarrayOrTensor) -> NdarrayOrTensor:
14111411
else:
14121412
img_t = self._normalize(img=img_t)
14131413

1414-
return convert_to_dst_type(img_t, dst=img)[0]
1414+
return convert_to_dst_type(img_t, dst=img, dtype=self.dtype)[0]
14151415

14161416

14171417
class MaskIntensity(Transform):

tests/test_scale_intensity_range_percentiles.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import unittest
1515

1616
import numpy as np
17+
import torch
1718

1819
from monai.transforms.intensity.array import ScaleIntensityRangePercentiles
1920
from tests.utils import TEST_NDARRAYS, NumpyImageTestCase2D, assert_allclose
@@ -34,6 +35,7 @@ def test_scaling(self):
3435
scaler = ScaleIntensityRangePercentiles(lower=lower, upper=upper, b_min=b_min, b_max=b_max, dtype=np.uint8)
3536
for p in TEST_NDARRAYS:
3637
result = scaler(p(img))
38+
self.assertEqual(result.dtype, torch.uint8)
3739
assert_allclose(result, p(expected), type_test="tensor", rtol=1e-4)
3840

3941
def test_relative_scaling(self):

0 commit comments

Comments
 (0)