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

Function get_2d_slice

monai/transforms/utils_create_transform_ims.py:280–294  ·  view source on GitHub ↗

If image is 3d, get the central slice. If is already 2d, return as-is. If image is label, set 0 to np.nan.

(image, view: int, is_label)

Source from the content-addressed store, hash-verified

278
279
280def get_2d_slice(image, view: int, is_label):
281 """If image is 3d, get the central slice. If is already 2d, return as-is.
282 If image is label, set 0 to np.nan.
283 """
284 if image.ndim == 2:
285 out = image
286 else:
287 shape = image.shape
288 slices = [slice(0, s) for s in shape]
289 _slice = shape[view] // 2
290 slices[view] = slice(_slice, _slice + 1)
291 out = np.squeeze(image[tuple(slices)], view)
292 if is_label:
293 out[out == 0] = np.nan
294 return out
295
296
297def get_stacked_2d_ims(im, is_label):

Callers 2

get_stacked_2d_imsFunction · 0.85
get_imagesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…