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

Method interp

monai/transforms/intensity/array.py:1871–1886  ·  view source on GitHub ↗
(self, x: NdarrayOrTensor, xp: NdarrayOrTensor, fp: NdarrayOrTensor)

Source from the content-addressed store, hash-verified

1869 self.floating_control_points: NdarrayOrTensor
1870
1871 def interp(self, x: NdarrayOrTensor, xp: NdarrayOrTensor, fp: NdarrayOrTensor) -> NdarrayOrTensor:
1872 ns = torch if isinstance(x, torch.Tensor) else np
1873 if isinstance(x, np.ndarray):
1874 # approx 2x faster than code below for ndarray
1875 return cast(np.ndarray, np.interp(x, xp, fp))
1876
1877 m = (fp[1:] - fp[:-1]) / (xp[1:] - xp[:-1])
1878 b = fp[:-1] - (m * xp[:-1])
1879
1880 indices = ns.searchsorted(xp.reshape(-1), x.reshape(-1)) - 1
1881 indices = ns.clip(indices, 0, len(m) - 1)
1882
1883 f: NdarrayOrTensor = (m[indices] * x.reshape(-1) + b[indices]).reshape(x.shape)
1884 f[x < xp[0]] = fp[0]
1885 f[x > xp[-1]] = fp[-1]
1886 return f
1887
1888 def randomize(self, data: Any | None = None) -> None:
1889 super().randomize(None)

Callers 4

__call__Method · 0.95
test_interpMethod · 0.95
compute_froc_scoreFunction · 0.80
equalize_histFunction · 0.80

Calls

no outgoing calls

Tested by 1

test_interpMethod · 0.76