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

Class ScaleIntensity

monai/transforms/intensity/array.py:445–497  ·  view source on GitHub ↗

Scale the intensity of input image to the given value range (minv, maxv). If `minv` and `maxv` not provided, use `factor` to scale image by ``v = v * (1 + factor)``.

Source from the content-addressed store, hash-verified

443
444
445class ScaleIntensity(Transform):
446 """
447 Scale the intensity of input image to the given value range (minv, maxv).
448 If `minv` and `maxv` not provided, use `factor` to scale image by ``v = v * (1 + factor)``.
449 """
450
451 backend = [TransformBackends.TORCH, TransformBackends.NUMPY]
452
453 def __init__(
454 self,
455 minv: float | None = 0.0,
456 maxv: float | None = 1.0,
457 factor: float | None = None,
458 channel_wise: bool = False,
459 dtype: DtypeLike = np.float32,
460 ) -> None:
461 """
462 Args:
463 minv: minimum value of output data.
464 maxv: maximum value of output data.
465 factor: factor scale by ``v = v * (1 + factor)``. In order to use
466 this parameter, please set both `minv` and `maxv` into None.
467 channel_wise: if True, scale on each channel separately. Please ensure
468 that the first dimension represents the channel of the image if True.
469 dtype: output data type, if None, same as input image. defaults to float32.
470 """
471 self.minv = minv
472 self.maxv = maxv
473 self.factor = factor
474 self.channel_wise = channel_wise
475 self.dtype = dtype
476
477 def __call__(self, img: NdarrayOrTensor) -> NdarrayOrTensor:
478 """
479 Apply the transform to `img`.
480
481 Raises:
482 ValueError: When ``self.minv=None`` or ``self.maxv=None`` and ``self.factor=None``. Incompatible values.
483
484 """
485 img = convert_to_tensor(img, track_meta=get_track_meta())
486 img_t = convert_to_tensor(img, track_meta=False)
487 ret: NdarrayOrTensor
488 if self.minv is not None or self.maxv is not None:
489 if self.channel_wise:
490 out = [rescale_array(d, self.minv, self.maxv, dtype=self.dtype) for d in img_t]
491 ret = torch.stack(out) # type: ignore
492 else:
493 ret = rescale_array(img_t, self.minv, self.maxv, dtype=self.dtype)
494 else:
495 ret = (img_t * (1 + self.factor)) if self.factor is not None else img_t
496 ret = convert_to_dst_type(ret, dst=img, dtype=self.dtype or img_t.dtype)[0]
497 return ret
498
499
500class ScaleIntensityFixedMean(Transform):

Callers 12

__init__Method · 0.90
gaussian_occlusionMethod · 0.90
_computeFunction · 0.90
run_training_testFunction · 0.90
run_inference_testFunction · 0.90
run_testFunction · 0.90
test_range_scaleMethod · 0.90
test_factor_scaleMethod · 0.90
test_max_noneMethod · 0.90
test_intMethod · 0.90
test_channel_wiseMethod · 0.90
__call__Method · 0.85

Calls

no outgoing calls

Tested by 8

run_training_testFunction · 0.72
run_inference_testFunction · 0.72
run_testFunction · 0.72
test_range_scaleMethod · 0.72
test_factor_scaleMethod · 0.72
test_max_noneMethod · 0.72
test_intMethod · 0.72
test_channel_wiseMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…