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

Method __call__

monai/transforms/intensity/array.py:2116–2155  ·  view source on GitHub ↗

Args: img: image with dimensions (C, H, W) or (C, H, W, D)

(self, img: NdarrayOrTensor)

Source from the content-addressed store, hash-verified

2114 raise ValueError("There must be one intensity_factor value for each tuple of indices in loc.")
2115
2116 def __call__(self, img: NdarrayOrTensor) -> NdarrayOrTensor:
2117 """
2118 Args:
2119 img: image with dimensions (C, H, W) or (C, H, W, D)
2120 """
2121 img = convert_to_tensor(img, track_meta=get_track_meta())
2122 # checking that tuples in loc are consistent with img size
2123 self._check_indices(img)
2124
2125 if len(img.shape) < 3:
2126 raise RuntimeError("Image needs a channel direction.")
2127 if isinstance(self.loc[0], int) and len(img.shape) == 4 and len(self.loc) == 2:
2128 raise RuntimeError("Input images of dimension 4 need location tuple to be length 3 or 4")
2129 if isinstance(self.loc[0], Sequence) and len(img.shape) == 4 and min(map(len, self.loc)) == 2:
2130 raise RuntimeError("Input images of dimension 4 need location tuple to be length 3 or 4")
2131
2132 n_dims = len(img.shape[1:])
2133
2134 # FT
2135 k = self.shift_fourier(img, n_dims)
2136 lib = np if isinstance(k, np.ndarray) else torch
2137 log_abs = lib.log(lib.abs(k) + 1e-10)
2138 phase = lib.angle(k)
2139
2140 k_intensity = self.k_intensity
2141 # default log intensity
2142 if k_intensity is None:
2143 k_intensity = tuple(lib.mean(log_abs, axis=tuple(range(-n_dims, 0))) * 2.5)
2144
2145 # highlight
2146 if isinstance(self.loc[0], Sequence):
2147 for idx, val in zip(self.loc, ensure_tuple(k_intensity)):
2148 self._set_spike(log_abs, idx, val)
2149 else:
2150 self._set_spike(log_abs, self.loc, k_intensity)
2151 # map back
2152 k = lib.exp(log_abs) * lib.exp(1j * phase)
2153 img, *_ = convert_to_dst_type(self.inv_shift_fourier(k, n_dims), dst=img)
2154
2155 return img
2156
2157 def _check_indices(self, img) -> None:
2158 """Helper method to check consistency of self.loc and input image.

Callers

nothing calls this directly

Calls 9

_check_indicesMethod · 0.95
_set_spikeMethod · 0.95
convert_to_tensorFunction · 0.90
get_track_metaFunction · 0.90
ensure_tupleFunction · 0.90
convert_to_dst_typeFunction · 0.90
minFunction · 0.85
shift_fourierMethod · 0.80
inv_shift_fourierMethod · 0.80

Tested by

no test coverage detected