diff --git a/monai/transforms/intensity/array.py b/monai/transforms/intensity/array.py index 8d7ebfbfe0..f24b184ec8 100644 --- a/monai/transforms/intensity/array.py +++ b/monai/transforms/intensity/array.py @@ -436,14 +436,14 @@ def __call__(self, img: NdarrayOrTensor) -> NdarrayOrTensor: if self.minv is not None and self.maxv is not None: if self.channel_wise: out = [rescale_array(d, self.minv, self.maxv, dtype=self.dtype) for d in img] - return torch.stack(out) if isinstance(img, torch.Tensor) else np.stack(out) # type: ignore - return rescale_array(img, self.minv, self.maxv, dtype=self.dtype) - if self.factor is not None: - ret = img * (1 + self.factor) - if self.dtype is not None: - ret, *_ = convert_data_type(ret, dtype=self.dtype or img.dtype) - return ret - raise ValueError("Incompatible values: minv=None or maxv=None and factor=None.") + ret = torch.stack(out) if isinstance(img, torch.Tensor) else np.stack(out) # type: ignore + else: + ret = rescale_array(img, self.minv, self.maxv, dtype=self.dtype) + else: + ret = (img * (1 + self.factor)) if self.factor is not None else img + + ret, *_ = convert_data_type(ret, dtype=self.dtype or img.dtype) + return ret class RandScaleIntensity(RandomizableTransform): diff --git a/monai/transforms/utils.py b/monai/transforms/utils.py index 1ba3c3e056..536a0b91ee 100644 --- a/monai/transforms/utils.py +++ b/monai/transforms/utils.py @@ -156,6 +156,13 @@ def rescale_array( ) -> NdarrayOrTensor: """ Rescale the values of numpy array `arr` to be from `minv` to `maxv`. + + Args: + arr: input array to rescale. + minv: minimum value of target rescaled array. + maxv: maxmum value of target rescaled array. + dtype: if not None, convert input array to dtype before computation. + """ if dtype is not None: arr, *_ = convert_data_type(arr, dtype=dtype)