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,
)
| 835 | |
| 836 | |
| 837 | def 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 | |
| 862 | def create_rotate( |
searching dependent graphs…