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,
)
| 759 | |
| 760 | |
| 761 | def 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 | |
| 793 | def _create_grid_numpy( |
searching dependent graphs…