MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / __call__

Method __call__

monai/transforms/intensity/array.py:2601–2623  ·  view source on GitHub ↗

Args: img: image to remap.

(self, img: torch.Tensor)

Source from the content-addressed store, hash-verified

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
2626class RandIntensityRemap(RandomizableTransform):

Callers

nothing calls this directly

Calls 3

convert_to_tensorFunction · 0.90
get_track_metaFunction · 0.90
convert_to_dst_typeFunction · 0.90

Tested by

no test coverage detected