Skip to content

Commit

Permalink
Fix dtype bug in ScaleIntensityRangePercentile (#8109)
Browse files Browse the repository at this point in the history
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 <55491388+KumoLiu@users.noreply.github.com>
  • Loading branch information
KumoLiu authored Sep 26, 2024
1 parent fa1c1af commit acfc508
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion monai/transforms/intensity/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -1411,7 +1411,7 @@ def __call__(self, img: NdarrayOrTensor) -> NdarrayOrTensor:
else:
img_t = self._normalize(img=img_t)

return convert_to_dst_type(img_t, dst=img)[0]
return convert_to_dst_type(img_t, dst=img, dtype=self.dtype)[0]


class MaskIntensity(Transform):
Expand Down
2 changes: 2 additions & 0 deletions tests/test_scale_intensity_range_percentiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import unittest

import numpy as np
import torch

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

def test_relative_scaling(self):
Expand Down

0 comments on commit acfc508

Please sign in to comment.