The function spm_sample_vol would do the job (although the output would need
to be reshaped to be a 3D array. The trilinear interpolation function
(RESAMPLE_1) is found in the file spm_vol_utils.c at about line 270. The function
is able to work on 3D (double precision) arrays if you pass them as:
ivol = spm_sample_vol(vol,xco,yco,zco,1);
ivol = reshape(vol,size(xco)); % Cos the output is always 2D
Alternatively, you can work with dynamic images if you tweek the volume handle.
I think the following should work for an Analyze format dynamic image:
V=spm_vol(filename);
V.pinfo(3) = V.pinfo(3) + (frame-1)*prod(dim(1:3))*spm_type(dim(4),'bits')/8;
I think your function would work better if you swapped around your "above"
and "below":
*(ivol+offset) = abovex*abovey*abovez*(*(vol+offsetxyz(xmin,ymin,zmin,plane,xdim)))+
abovex*abovey*belowz*(*(vol+offsetxyz(xmin,ymin,zmax,plane,xdim)))+
abovex*belowy*abovez*(*(vol+offsetxyz(xmin,ymax,zmin,plane,xdim)))....
All the best,
-John
| This is a question for the (C-)programmers in the user group. I'm having
| strange effects when I try to carry out a trilinear interpolation.
| I'm working on a program that transforms dynamic ECAT files, having
| calculated the transformation with SPM routines. The transformation must
| be the same for every frame, so the quickest way to do this is to build
| a 3d mesh grid once, and interpolate all frames on that grid.
| The interp3.m interpolation function in Matlab is very slow, so I
| decided to write a quick C/mexsol file to carry out the interpolation.
| The interpolation now takes about 9 seconds per frame, instead of the
| previous 45 seconds. But the images produced by the Matlab routine are
| much smoother than those produced by my own routine. Another effect is a
| high background signal.
| Does anybody know what I'm doing wrong? Are there any steps I've
| forgotten (like for the boundaries of the volume)?
| Included are the source file of my interpolation routine, a screen shot
| of a transformed file interpolated by my own routine, and a screen shot
| of a transformed file interpolated by Matlab's interp3 function.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|