Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions monai/transforms/intensity/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
7 changes: 7 additions & 0 deletions monai/transforms/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down