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
| 949 | |
| 950 | |
| 951 | class 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 | |
| 982 | class ScaleIntensityRange(Transform): |
no outgoing calls
searching dependent graphs…