MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / ThresholdIntensity

Class ThresholdIntensity

monai/transforms/intensity/array.py:951–979  ·  view source on GitHub ↗

Filter the intensity values of whole image to below threshold or above threshold. And fill the remaining parts of the image to the `cval` value. Args: threshold: the threshold to filter intensity values. above: filter values above the threshold or below the threshold, d

Source from the content-addressed store, hash-verified

949
950
951class ThresholdIntensity(Transform):
952 """
953 Filter the intensity values of whole image to below threshold or above threshold.
954 And fill the remaining parts of the image to the `cval` value.
955
956 Args:
957 threshold: the threshold to filter intensity values.
958 above: filter values above the threshold or below the threshold, default is True.
959 cval: value to fill the remaining parts of the image, default is 0.
960 """
961
962 backend = [TransformBackends.TORCH, TransformBackends.NUMPY]
963
964 def __init__(self, threshold: float, above: bool = True, cval: float = 0.0) -> None:
965 if not isinstance(threshold, (int, float)):
966 raise ValueError(f"threshold must be a float or int number, got {type(threshold)} {threshold}.")
967 self.threshold = threshold
968 self.above = above
969 self.cval = cval
970
971 def __call__(self, img: NdarrayOrTensor) -> NdarrayOrTensor:
972 """
973 Apply the transform to `img`.
974 """
975 img = convert_to_tensor(img, track_meta=get_track_meta())
976 mask = img > self.threshold if self.above else img < self.threshold
977 res = where(mask, img, self.cval)
978 res, *_ = convert_data_type(res, dtype=img.dtype)
979 return res
980
981
982class ScaleIntensityRange(Transform):

Callers 2

__init__Method · 0.90
test_valueMethod · 0.90

Calls

no outgoing calls

Tested by 1

test_valueMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…