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

Function create_grid

monai/transforms/utils.py:761–790  ·  view source on GitHub ↗

compute a `spatial_size` mesh. - when ``homogeneous=True``, the output shape is (N+1, dim_size_1, dim_size_2, ..., dim_size_N) - when ``homogeneous=False``, the output shape is (N, dim_size_1, dim_size_2, ..., dim_size_N) Args: spatial_size: spatial size of the gri

(
    spatial_size: Sequence[int],
    spacing: Sequence[float] | None = None,
    homogeneous: bool = True,
    dtype: DtypeLike | torch.dtype = float,
    device: torch.device | None = None,
    backend=TransformBackends.NUMPY,
)

Source from the content-addressed store, hash-verified

759
760
761def create_grid(
762 spatial_size: Sequence[int],
763 spacing: Sequence[float] | None = None,
764 homogeneous: bool = True,
765 dtype: DtypeLike | torch.dtype = float,
766 device: torch.device | None = None,
767 backend=TransformBackends.NUMPY,
768) -> NdarrayOrTensor:
769 """
770 compute a `spatial_size` mesh.
771
772 - when ``homogeneous=True``, the output shape is (N+1, dim_size_1, dim_size_2, ..., dim_size_N)
773 - when ``homogeneous=False``, the output shape is (N, dim_size_1, dim_size_2, ..., dim_size_N)
774
775 Args:
776 spatial_size: spatial size of the grid.
777 spacing: same len as ``spatial_size``, defaults to 1.0 (dense grid).
778 homogeneous: whether to make homogeneous coordinates.
779 dtype: output grid data type, defaults to `float`.
780 device: device to compute and store the output (when the backend is "torch").
781 backend: APIs to use, ``numpy`` or ``torch``.
782
783 """
784 _backend = look_up_option(backend, TransformBackends)
785 _dtype = dtype or float
786 if _backend == TransformBackends.NUMPY:
787 return _create_grid_numpy(spatial_size, spacing, homogeneous, _dtype) # type: ignore
788 if _backend == TransformBackends.TORCH:
789 return _create_grid_torch(spatial_size, spacing, homogeneous, _dtype, device) # type: ignore
790 raise ValueError(f"backend {backend} is not supported")
791
792
793def _create_grid_numpy(

Callers 11

__call__Method · 0.90
__call__Method · 0.90
__call__Method · 0.90
_init_identity_cacheMethod · 0.90
get_identity_gridMethod · 0.90
__call__Method · 0.90
__call__Method · 0.90
test_resampler.pyFile · 0.90
test_create_gridMethod · 0.90
create_control_gridFunction · 0.85

Calls 3

look_up_optionFunction · 0.90
_create_grid_numpyFunction · 0.85
_create_grid_torchFunction · 0.85

Tested by 2

test_create_gridMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…