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

Method __call__

monai/transforms/intensity/array.py:814–836  ·  view source on GitHub ↗

Apply the transform to `img`.

(self, img: NdarrayOrTensor, randomize: bool = True)

Source from the content-addressed store, hash-verified

812 self._coeff = self.R.uniform(*self.coeff_range, n_coeff).tolist()
813
814 def __call__(self, img: NdarrayOrTensor, randomize: bool = True) -> NdarrayOrTensor:
815 """
816 Apply the transform to `img`.
817 """
818 img = convert_to_tensor(img, track_meta=get_track_meta())
819 if randomize:
820 self.randomize(img_size=img.shape[1:])
821
822 if not self._do_transform:
823 return img
824
825 num_channels, *spatial_shape = img.shape
826 _bias_fields = np.stack(
827 [
828 self._generate_random_field(spatial_shape=spatial_shape, degree=self.degree, coeff=self._coeff)
829 for _ in range(num_channels)
830 ],
831 axis=0,
832 )
833 img_np, *_ = convert_data_type(img, np.ndarray)
834 out: NdarrayOrTensor = img_np * np.exp(_bias_fields)
835 out, *_ = convert_to_dst_type(src=out, dst=img, dtype=self.dtype or img.dtype)
836 return out
837
838
839class NormalizeIntensity(Transform):

Callers

nothing calls this directly

Calls 6

randomizeMethod · 0.95
convert_to_tensorFunction · 0.90
get_track_metaFunction · 0.90
convert_data_typeFunction · 0.90
convert_to_dst_typeFunction · 0.90

Tested by

no test coverage detected