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

Function create_control_grid

monai/transforms/utils.py:837–859  ·  view source on GitHub ↗

control grid with two additional point in each direction

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

Source from the content-addressed store, hash-verified

835
836
837def create_control_grid(
838 spatial_shape: Sequence[int],
839 spacing: Sequence[float],
840 homogeneous: bool = True,
841 dtype: DtypeLike = float,
842 device: torch.device | None = None,
843 backend=TransformBackends.NUMPY,
844):
845 """
846 control grid with two additional point in each direction
847 """
848 torch_backend = look_up_option(backend, TransformBackends) == TransformBackends.TORCH
849 ceil_func: Callable = torch.ceil if torch_backend else np.ceil # type: ignore
850 grid_shape = []
851 for d, s in zip(spatial_shape, spacing):
852 d = torch.as_tensor(d, device=device) if torch_backend else int(d) # type: ignore
853 if d % 2 == 0:
854 grid_shape.append(ceil_func((d - 1.0) / (2.0 * s) + 0.5) * 2.0 + 2.0)
855 else:
856 grid_shape.append(ceil_func((d - 1.0) / (2.0 * s)) * 2.0 + 3.0)
857 return create_grid(
858 spatial_size=grid_shape, spacing=spacing, homogeneous=homogeneous, dtype=dtype, device=device, backend=backend
859 )
860
861
862def create_rotate(

Callers 2

__call__Method · 0.90

Calls 4

look_up_optionFunction · 0.90
create_gridFunction · 0.85
as_tensorMethod · 0.80
appendMethod · 0.45

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…