Apply the transform to `img`.
(self, img: NdarrayOrTensor, randomize: bool = True)
| 202 | return np.sqrt((img + self._noise1) ** 2 + self._noise2**2) |
| 203 | |
| 204 | def __call__(self, img: NdarrayOrTensor, randomize: bool = True) -> NdarrayOrTensor: |
| 205 | """ |
| 206 | Apply the transform to `img`. |
| 207 | """ |
| 208 | img = convert_to_tensor(img, track_meta=get_track_meta(), dtype=self.dtype) |
| 209 | if randomize: |
| 210 | super().randomize(None) |
| 211 | |
| 212 | if not self._do_transform: |
| 213 | return img |
| 214 | |
| 215 | if self.channel_wise: |
| 216 | _mean = ensure_tuple_rep(self.mean, len(img)) |
| 217 | _std = ensure_tuple_rep(self.std, len(img)) |
| 218 | for i, d in enumerate(img): |
| 219 | img[i] = self._add_noise(d, mean=_mean[i], std=_std[i] * d.std() if self.relative else _std[i]) |
| 220 | else: |
| 221 | if not isinstance(self.mean, (int, float)): |
| 222 | raise RuntimeError(f"If channel_wise is False, mean must be a float or int, got {type(self.mean)}.") |
| 223 | if not isinstance(self.std, (int, float)): |
| 224 | raise RuntimeError(f"If channel_wise is False, std must be a float or int, got {type(self.std)}.") |
| 225 | std = self.std * img.std().item() if self.relative else self.std |
| 226 | if not isinstance(std, (int, float)): |
| 227 | raise RuntimeError(f"std must be a float or int number, got {type(std)}.") |
| 228 | img = self._add_noise(img, mean=self.mean, std=std) |
| 229 | return img |
| 230 | |
| 231 | |
| 232 | class ShiftIntensity(Transform): |
nothing calls this directly
no test coverage detected