@@ -27,18 +27,18 @@ def _cubic_bspline(d, order=3):
2727 )
2828
2929
30- def grid_bspline_weights (target_nii , ctrl_nii ):
30+ def grid_bspline_weights (target_grid , ctrl_grid ):
3131 r"""
3232 Evaluate tensor-product B-Spline weights on a grid.
3333
34- For each of the *N* input samples :math:`(s_1, s_2, s_3)` and *K* control
35- points or *knots* :math:`\mathbf{k } =(k_1, k_2, k_3 )`, the tensor-product
36- cubic B-Spline kernel weights are calculated:
34+ For each of the :math:`N` input locations :math:`\mathbf{x} = (x_i, x_j, x_k)`
35+ and :math:`K` control points or *knots* :math:`\mathbf{c } =(c_i, c_j, c_k )`,
36+ the tensor-product cubic B-Spline kernel weights are calculated:
3737
3838 .. math::
39- \Psi^3(\mathbf{k }, \mathbf{s }) =
40- \beta^3(s_1 - k_1 ) \cdot \beta^3(s_2 - k_2 ) \cdot \beta^3(s_3 - k_3 ),
41- \label{eq:1 }\tag{1}
39+ \Psi^3(\mathbf{x }, \mathbf{c }) =
40+ \beta^3(x_i - c_i ) \cdot \beta^3(x_j - c_j ) \cdot \beta^3(x_k - c_k ),
41+ \label{eq:bspline_weights }\tag{1}
4242
4343 where each :math:`\beta^3` represents the cubic B-Spline for one dimension.
4444 The 1D B-Spline kernel implementation uses :obj:`numpy.piecewise`, and is based on the
@@ -54,14 +54,10 @@ def grid_bspline_weights(target_nii, ctrl_nii):
5454
5555 Parameters
5656 ----------
57- target_nii : :obj:`nibabel.spatialimages`
58- An spatial image object (typically, a :obj:`~nibabel.nifti1.Nifti1Image`)
59- embedding the target EPI image to be corrected.
60- Provides the location of the *N* samples (total number of voxels) in the space.
61- ctrl_nii : :obj:`nibabel.spatialimages`
62- An spatial image object (typically, a :obj:`~nibabel.nifti1.Nifti1Image`)
63- embedding the location of the control points of the B-Spline grid.
64- The data array should contain a total of :math:`K` knots (control points).
57+ target_grid : :obj:`~nitransforms.base.ImageGrid` or :obj:`nibabel.spatialimages`
58+ Regular grid of :math:`N` locations at which tensor B-Spline basis will be evaluated.
59+ ctrl_grid : :obj:`~nitransforms.base.ImageGrid` or :obj:`nibabel.spatialimages`
60+ Regular grid of :math:`K` control points (knot) where B-Spline basis are defined.
6561
6662 Returns
6763 -------
@@ -72,19 +68,19 @@ def grid_bspline_weights(target_nii, ctrl_nii):
7268 step of approximation/extrapolation.
7369
7470 """
75- shape = target_nii .shape [:3 ]
76- ctrl_sp = nb .affines .voxel_sizes (ctrl_nii .affine )[:3 ]
77- ras2ijk = np .linalg .inv (ctrl_nii .affine )
71+ shape = target_grid .shape [:3 ]
72+ ctrl_sp = nb .affines .voxel_sizes (ctrl_grid .affine )[:3 ]
73+ ras2ijk = np .linalg .inv (ctrl_grid .affine )
7874 # IJK index in the control point image of the first index in the target image
79- origin = nb .affines .apply_affine (ras2ijk , [tuple (target_nii .affine [:3 , 3 ])])[0 ]
75+ origin = nb .affines .apply_affine (ras2ijk , [tuple (target_grid .affine [:3 , 3 ])])[0 ]
8076
8177 wd = []
8278 for i , (o , n , sp ) in enumerate (
83- zip (origin , shape , nb .affines .voxel_sizes (target_nii .affine )[:3 ])
79+ zip (origin , shape , nb .affines .voxel_sizes (target_grid .affine )[:3 ])
8480 ):
8581 # Locations of voxels in target image in control point image
8682 locations = np .arange (0 , n , dtype = "float16" ) * sp / ctrl_sp [i ] + o
87- knots = np .arange (0 , ctrl_nii .shape [i ], dtype = "float16" )
83+ knots = np .arange (0 , ctrl_grid .shape [i ], dtype = "float16" )
8884 distance = np .abs (locations [np .newaxis , ...] - knots [..., np .newaxis ])
8985
9086 within_support = distance < 2.0
0 commit comments