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

Method __call__

monai/transforms/utility/array.py:313–334  ·  view source on GitHub ↗

Apply the transform to `img`.

(self, img: torch.Tensor)

Source from the content-addressed store, hash-verified

311 self.update_meta = update_meta
312
313 def __call__(self, img: torch.Tensor) -> list[torch.Tensor]:
314 """
315 Apply the transform to `img`.
316 """
317 n_out = img.shape[self.dim]
318 if isinstance(img, torch.Tensor):
319 outputs = list(torch.split(img, 1, self.dim))
320 else:
321 outputs = np.split(img, n_out, self.dim)
322 for idx, item in enumerate(outputs):
323 if not self.keepdim:
324 outputs[idx] = item.squeeze(self.dim)
325 if self.update_meta and isinstance(img, MetaTensor):
326 if not isinstance(item, MetaTensor):
327 item = MetaTensor(item, meta=img.meta)
328 if self.dim == 0: # don't update affine if channel dim
329 continue
330 ndim = len(item.affine)
331 shift = torch.eye(ndim, device=item.affine.device, dtype=item.affine.dtype)
332 shift[self.dim - 1, -1] = idx
333 item.affine = item.affine @ shift
334 return outputs
335
336
337class CastToType(Transform):

Callers

nothing calls this directly

Calls 2

MetaTensorClass · 0.90
splitMethod · 0.80

Tested by

no test coverage detected