MCPcopy Index your code
hub / github.com/Project-MONAI/MONAI / rescale_array

Function rescale_array

monai/transforms/utils.py:232–260  ·  view source on GitHub ↗

Rescale the values of numpy array `arr` to be from `minv` to `maxv`. If either `minv` or `maxv` is None, it returns `(a - min_a) / (max_a - min_a)`. Args: arr: input array to rescale. minv: minimum value of target rescaled array. maxv: maximum value of target re

(
    arr: NdarrayOrTensor,
    minv: float | None = 0.0,
    maxv: float | None = 1.0,
    dtype: DtypeLike | torch.dtype = np.float32,
)

Source from the content-addressed store, hash-verified

230
231
232def rescale_array(
233 arr: NdarrayOrTensor,
234 minv: float | None = 0.0,
235 maxv: float | None = 1.0,
236 dtype: DtypeLike | torch.dtype = np.float32,
237) -> NdarrayOrTensor:
238 """
239 Rescale the values of numpy array `arr` to be from `minv` to `maxv`.
240 If either `minv` or `maxv` is None, it returns `(a - min_a) / (max_a - min_a)`.
241
242 Args:
243 arr: input array to rescale.
244 minv: minimum value of target rescaled array.
245 maxv: maximum value of target rescaled array.
246 dtype: if not None, convert input array to dtype before computation.
247
248 """
249 if dtype is not None:
250 arr, *_ = convert_data_type(arr, dtype=dtype)
251 mina = arr.min()
252 maxa = arr.max()
253
254 if mina == maxa:
255 return arr * minv if minv is not None else arr
256
257 norm = (arr - mina) / (maxa - mina) # normalize the array first
258 if (minv is None) or (maxv is None):
259 return norm
260 return (norm * (maxv - minv)) + minv # rescale by minv and maxv, which is the normalized array by default
261
262
263def rescale_instance_array(

Callers 9

create_test_image_2dFunction · 0.90
create_test_image_3dFunction · 0.90
__call__Method · 0.90
blend_imagesFunction · 0.90
plot_2d_or_3d_imageFunction · 0.90
test_max_noneMethod · 0.90
rescale_instance_arrayFunction · 0.85
rescale_array_int_maxFunction · 0.85
equalize_histFunction · 0.85

Calls 1

convert_data_typeFunction · 0.90

Tested by 1

test_max_noneMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…