Args: img: image to remap.
(self, img: torch.Tensor)
| 2599 | self.slope = slope |
| 2600 | |
| 2601 | def __call__(self, img: torch.Tensor) -> torch.Tensor: |
| 2602 | """ |
| 2603 | Args: |
| 2604 | img: image to remap. |
| 2605 | """ |
| 2606 | img = convert_to_tensor(img, track_meta=get_track_meta()) |
| 2607 | img_ = convert_to_tensor(img, track_meta=False) |
| 2608 | # sample noise |
| 2609 | vals_to_sample = torch.unique(img_).tolist() |
| 2610 | noise = torch.from_numpy(self.R.choice(vals_to_sample, len(vals_to_sample) - 1 + self.kernel_size)) |
| 2611 | # smooth |
| 2612 | noise = torch.nn.AvgPool1d(self.kernel_size, stride=1)(noise.unsqueeze(0)).squeeze() |
| 2613 | # add linear component |
| 2614 | grid = torch.arange(len(noise)) / len(noise) |
| 2615 | noise += self.slope * grid |
| 2616 | # rescale |
| 2617 | noise = (noise - noise.min()) / (noise.max() - noise.min()) * img_.max() + img_.min() |
| 2618 | |
| 2619 | # intensity remapping function |
| 2620 | index_img = torch.bucketize(img_, torch.tensor(vals_to_sample)) |
| 2621 | img, *_ = convert_to_dst_type(noise[index_img], dst=img) |
| 2622 | |
| 2623 | return img |
| 2624 | |
| 2625 | |
| 2626 | class RandIntensityRemap(RandomizableTransform): |
nothing calls this directly
no test coverage detected