Helper method to sample both the location and intensity of the spikes. When not working channel wise (channel_wise=False) it use the random variable ``self._do_transform`` to decide whether to sample a location and intensity. When working channel wise, the m
(self, img: NdarrayOrTensor, intensity_range: Sequence[Sequence[float]])
| 2272 | return KSpaceSpikeNoise(self.sampled_locs, self.sampled_k_intensity)(img) |
| 2273 | |
| 2274 | def randomize(self, img: NdarrayOrTensor, intensity_range: Sequence[Sequence[float]]) -> None: # type: ignore |
| 2275 | """ |
| 2276 | Helper method to sample both the location and intensity of the spikes. |
| 2277 | When not working channel wise (channel_wise=False) it use the random |
| 2278 | variable ``self._do_transform`` to decide whether to sample a location |
| 2279 | and intensity. |
| 2280 | |
| 2281 | When working channel wise, the method randomly samples a location and |
| 2282 | intensity for each channel depending on ``self._do_transform``. |
| 2283 | """ |
| 2284 | super().randomize(None) |
| 2285 | if not self._do_transform: |
| 2286 | return None |
| 2287 | if self.channel_wise: |
| 2288 | # randomizing per channel |
| 2289 | for i, chan in enumerate(img): |
| 2290 | self.sampled_locs.append((i,) + tuple(self.R.randint(0, k) for k in chan.shape)) |
| 2291 | self.sampled_k_intensity.append(self.R.uniform(intensity_range[i][0], intensity_range[i][1])) |
| 2292 | else: |
| 2293 | # working with all channels together |
| 2294 | spatial = tuple(self.R.randint(0, k) for k in img.shape[1:]) |
| 2295 | self.sampled_locs = [(i,) + spatial for i in range(img.shape[0])] |
| 2296 | if isinstance(intensity_range[0], Sequence): |
| 2297 | self.sampled_k_intensity = [self.R.uniform(p[0], p[1]) for p in intensity_range] |
| 2298 | else: |
| 2299 | self.sampled_k_intensity = [self.R.uniform(intensity_range[0], intensity_range[1])] * len(img) |
| 2300 | |
| 2301 | def _make_sequence(self, x: NdarrayOrTensor) -> Sequence[Sequence[float]]: |
| 2302 | """ |