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

Method __call__

monai/transforms/croppad/array.py:408–425  ·  view source on GitHub ↗

Apply the transform to `img`, assuming `img` is channel-first and slicing doesn't apply to the channel dim.

(  # type: ignore[override]
        self, img: torch.Tensor, slices: tuple[slice, ...], lazy: bool | None = None
    )

Source from the content-addressed store, hash-verified

406 return ensure_tuple([slice(int(s), int(e)) for s, e in zip(roi_start_t.tolist(), roi_end_t.tolist())])
407
408 def __call__( # type: ignore[override]
409 self, img: torch.Tensor, slices: tuple[slice, ...], lazy: bool | None = None
410 ) -> torch.Tensor:
411 """
412 Apply the transform to `img`, assuming `img` is channel-first and
413 slicing doesn't apply to the channel dim.
414
415 """
416 slices_ = list(slices)
417 sd = len(img.peek_pending_shape() if isinstance(img, MetaTensor) else img.shape[1:]) # spatial dims
418 if len(slices_) < sd:
419 slices_ += [slice(None)] * (sd - len(slices_))
420 # Add in the channel (no cropping)
421 slices_ = list([slice(None)] + slices_[:sd])
422
423 img_t: MetaTensor = convert_to_tensor(data=img, track_meta=get_track_meta())
424 lazy_ = self.lazy if lazy is None else lazy
425 return crop_func(img_t, tuple(slices_), lazy_, self.get_transform_info())
426
427 def inverse(self, img: MetaTensor) -> MetaTensor:
428 transform = self.pop_transform(img)

Callers

nothing calls this directly

Calls 5

convert_to_tensorFunction · 0.90
get_track_metaFunction · 0.90
crop_funcFunction · 0.90
peek_pending_shapeMethod · 0.80
get_transform_infoMethod · 0.80

Tested by

no test coverage detected