Print

Print


Yong Zhang wrote:
> When I performed a cubic B-spline interpolation (d=3) in SPM to reconstruct
> the 3D displacement, I got very  strange warping.  But the first degree
> spline could work.  I checked spm_bspinc.c and spm_bspins.c. 
> In spm_bsplines.c, I found the following words, "Should really combine
> this function with wt2 to wt7 for most efficiency." 
> 
> I am not sure if it means that we can only use 0 or first degree 
> b-spline in SPM.
> If I want to use cubic b-spline, what should I do?

Did you use both spm_bsplinc and spm_bsplins with a degree of 3? When 
you compute the basis function coefficients for 7th-degree splines and 
then interpolate with a 3rd-degree interpolant, you may expect to see 
some weird things.

As for the comment "should really combine...", that is a programmer's 
comment - don't know if it's from John Ashburner or Philippe Thevenaz. 
It means that instead of having the separate functions wt2..wt7, it 
would be faster to put all that code inside the case-statement in 
spm_bsplins.c (as has been done for wt0 and wt1).

If you want a cubic spline interpolation you need to do something like this:

% load image
V=spm_vol(`file.img');
v=spm_read_vols(V);
% make new grid with step 1.5 * smaller -> resolution 1.5 * bigger
step=0.66;
[x,y,z]=ndgrid(1:step:V.dim(1),1:step:V.dim(2),1:step:V.dim(3));
v1=spm_bsplinc(im,3);
w1=spm_bsplins(v1,x,y,z,3);

w1 should then be the resampled image.
If you get strange reults due to wraparound effects, you might want to 
change the boundary conditions from wrap(1) to mirror(0). The last 2 
lines then become:

v1=spm_bsplinc(im,[3 3 3 0 0 0]);
w1=spm_bsplins(v1,x,y,z,[3 3 3 0 0 0]);

It may be worth studying the code a bit before doing wilder things...

Best regards
Alle Meije Wink