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

Method __call__

monai/transforms/spatial/array.py:440–547  ·  view source on GitHub ↗

Args: data_array: in shape (num_channels, H[, W, ...]). mode: {``"bilinear"``, ``"nearest"``} or spline interpolation order 0-5 (integers). Interpolation mode to calculate output values. Defaults to ``"self.mode"``. See also: https://p

(
        self,
        data_array: torch.Tensor,
        mode: str | int | None = None,
        padding_mode: str | None = None,
        align_corners: bool | None = None,
        dtype: DtypeLike = None,
        scale_extent: bool | None = None,
        output_spatial_shape: Sequence[int] | np.ndarray | int | None = None,
        lazy: bool | None = None,
    )

Source from the content-addressed store, hash-verified

438 self.sp_resample.lazy = val
439
440 def __call__(
441 self,
442 data_array: torch.Tensor,
443 mode: str | int | None = None,
444 padding_mode: str | None = None,
445 align_corners: bool | None = None,
446 dtype: DtypeLike = None,
447 scale_extent: bool | None = None,
448 output_spatial_shape: Sequence[int] | np.ndarray | int | None = None,
449 lazy: bool | None = None,
450 ) -> torch.Tensor:
451 """
452 Args:
453 data_array: in shape (num_channels, H[, W, ...]).
454 mode: {``"bilinear"``, ``"nearest"``} or spline interpolation order 0-5 (integers).
455 Interpolation mode to calculate output values. Defaults to ``"self.mode"``.
456 See also: https://pytorch.org/docs/stable/generated/torch.nn.functional.grid_sample.html
457 When it's an integer, the numpy (cpu tensor)/cupy (cuda tensor) backends will be used
458 and the value represents the order of the spline interpolation.
459 See also: https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.map_coordinates.html
460 padding_mode: {``"zeros"``, ``"border"``, ``"reflection"``}
461 Padding mode for outside grid values. Defaults to ``"self.padding_mode"``.
462 See also: https://pytorch.org/docs/stable/generated/torch.nn.functional.grid_sample.html
463 When `mode` is an integer, using numpy/cupy backends, this argument accepts
464 {'reflect', 'grid-mirror', 'constant', 'grid-constant', 'nearest', 'mirror', 'grid-wrap', 'wrap'}.
465 See also: https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.map_coordinates.html
466 align_corners: Geometrically, we consider the pixels of the input as squares rather than points.
467 See also: https://pytorch.org/docs/stable/generated/torch.nn.functional.grid_sample.html
468 Defaults to ``None``, effectively using the value of `self.align_corners`.
469 dtype: data type for resampling computation. Defaults to ``self.dtype``.
470 If None, use the data type of input data. To be compatible with other modules,
471 the output data type is always ``float32``.
472 scale_extent: whether the scale is computed based on the spacing or the full extent of voxels,
473 The option is ignored if output spatial size is specified when calling this transform.
474 See also: :py:func:`monai.data.utils.compute_shape_offset`. When this is True, `align_corners`
475 should be `True` because `compute_shape_offset` already provides the corner alignment shift/scaling.
476 output_spatial_shape: specify the shape of the output data_array. This is typically useful for
477 the inverse of `Spacingd` where sometimes we could not compute the exact shape due to the quantization
478 error with the affine.
479 lazy: a flag to indicate whether this transform should execute lazily or not
480 during this call. Setting this to False or True overrides the ``lazy`` flag set
481 during initialization for this call. Defaults to None.
482
483 Raises:
484 ValueError: When ``data_array`` has no spatial dimensions.
485 ValueError: When ``pixdim`` is nonpositive.
486
487 Returns:
488 data tensor or MetaTensor (resampled into `self.pixdim`).
489
490 """
491 original_spatial_shape = (
492 data_array.peek_pending_shape() if isinstance(data_array, MetaTensor) else data_array.shape[1:]
493 )
494 sr = len(original_spatial_shape)
495 if sr <= 0:
496 raise ValueError(f"data_array must have at least one spatial dimension, got {original_spatial_shape}.")
497 affine_: np.ndarray

Callers

nothing calls this directly

Calls 13

to_affine_ndFunction · 0.90
convert_data_typeFunction · 0.90
affine_to_spacingFunction · 0.90
zoom_affineFunction · 0.90
compute_shape_offsetFunction · 0.90
scale_affineFunction · 0.90
convert_to_dst_typeFunction · 0.90
minFunction · 0.85
maxFunction · 0.85
peek_pending_shapeMethod · 0.80
peek_pending_affineMethod · 0.80
as_tensorMethod · 0.80

Tested by

no test coverage detected