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

Function requires_interp

monai/transforms/lazy/utils.py:122–152  ·  view source on GitHub ↗

Check whether the transformation matrix suggests voxel-wise interpolation. Returns None if the affine matrix suggests interpolation. Otherwise, the matrix suggests that the resampling could be achieved by simple array operations such as flip/permute/pad_nd/slice; in this case this

(matrix, atol=AFFINE_TOL)

Source from the content-addressed store, hash-verified

120
121
122def requires_interp(matrix, atol=AFFINE_TOL):
123 """
124 Check whether the transformation matrix suggests voxel-wise interpolation.
125
126 Returns None if the affine matrix suggests interpolation.
127 Otherwise, the matrix suggests that the resampling could be achieved by simple array operations
128 such as flip/permute/pad_nd/slice; in this case this function returns axes information about simple axes
129 operations.
130
131 Args:
132 matrix: the affine matrix to check.
133 atol: absolute tolerance for checking if the matrix is close to an integer.
134 """
135 matrix = convert_to_numpy(matrix, wrap_sequence=True)
136 s = matrix[:, -1]
137 if not np.allclose(s, np.round(s), atol=atol):
138 return None
139
140 ndim = len(matrix) - 1
141 ox, oy = [], [0]
142 for x, r in enumerate(matrix[:ndim, :ndim]):
143 for y, c in enumerate(r):
144 if np.isclose(c, -1, atol=atol) or np.isclose(c, 1, atol=atol):
145 y_channel = y + 1 # the returned axis index starting with channel dim
146 if x in ox or y_channel in oy:
147 return None
148 ox.append(x)
149 oy.append(y_channel)
150 elif not np.isclose(c, 0.0, atol=atol):
151 return None
152 return oy
153
154
155__override_lazy_keywords = {*list(LazyAttr), "atol"}

Callers 1

resampleFunction · 0.85

Calls 2

convert_to_numpyFunction · 0.90
appendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…