Apply the transform to `img`, assuming `img` is a channel-first array if `self.channel_wise` is True,
(self, img: NdarrayOrTensor)
| 920 | return img |
| 921 | |
| 922 | def __call__(self, img: NdarrayOrTensor) -> NdarrayOrTensor: |
| 923 | """ |
| 924 | Apply the transform to `img`, assuming `img` is a channel-first array if `self.channel_wise` is True, |
| 925 | """ |
| 926 | img_t: torch.Tensor = convert_to_tensor(img, track_meta=get_track_meta()) # type: ignore[assignment] |
| 927 | dtype = self.dtype or img.dtype |
| 928 | img_len = len(img_t) |
| 929 | if self.channel_wise: |
| 930 | if self.subtrahend is not None and len(self.subtrahend) != img_len: |
| 931 | raise ValueError(f"img has {img_len} channels, but subtrahend has {len(self.subtrahend)} components.") |
| 932 | if self.divisor is not None and len(self.divisor) != img_len: |
| 933 | raise ValueError(f"img has {img_len} channels, but divisor has {len(self.divisor)} components.") |
| 934 | |
| 935 | if not img_t.dtype.is_floating_point: |
| 936 | img_t, *_ = convert_data_type(img_t, dtype=torch.float32) |
| 937 | |
| 938 | for i, d in enumerate(img_t): |
| 939 | img_t[i] = self._normalize( # type: ignore |
| 940 | d, |
| 941 | sub=self.subtrahend[i] if self.subtrahend is not None else None, |
| 942 | div=self.divisor[i] if self.divisor is not None else None, |
| 943 | ) |
| 944 | else: |
| 945 | img_t = self._normalize(img_t, self.subtrahend, self.divisor) # type: ignore[assignment] |
| 946 | |
| 947 | out = convert_to_dst_type(img_t, img_t, dtype=dtype)[0] |
| 948 | return out |
| 949 | |
| 950 | |
| 951 | class ThresholdIntensity(Transform): |
nothing calls this directly
no test coverage detected