B-spline interpolation is quite different from the polynomial
interpolation. In fact, I would not recommend polynomial interpolation
with a degree greater than 1 (trilinear) as the gradients will not be
continuous.
B-spline interpolation is a generalized interpolation method. For
degrees greater than 1, it begins by generating an image of coefficients
(a deconvolution procedure done by spm_bsplinc). These can be thought
of as basis function coefficients, where there is a local basis function
centered on each voxel. These coefficients are then used, along with
the amplitudes of the basis functions at the new points, to resample the
image (via spm_bsplins).
B-splines are the recommended interpolation approach.
Best regards,
-John
-----Original Message-----
From: SPM (Statistical Parametric Mapping) [mailto:[log in to unmask]]
On Behalf Of Ged Ridgway
Sent: Wednesday, September 27, 2006 5:06 PM
To: [log in to unmask]
Subject: Re: [SPM] write deformations
Hi Mark,
Looks a useful hack! Do you by any chance know the answer to my
earlier confusion:
"spm_sample_vol seems to offer sinc or polynomial, but not b-spline"
I see in your help you refer to nth order B-spline interpolation, but
I think the help for spm_sample_vol refers instead to Lagrange
polynomial interpolation; I didn't think these were the same, but
maybe I'm wrong about that... I guess B-splines are piecewise
polynomials... Do you (and/or any other readers) think they are
different names for the same thing? (I haven't looked through the C
code to see what's actually done!)
Best,
Ged.
Mark Daglish wrote:
> Hi Siawoosh,
>
> I hacked the attached version of spm_applydef_ui.m to allow me to
choose
> the resampling option when applying a deformation field to an image.
I
> wanted nearest neighbour so I could resample object maps. It offers a
> choice of the interpolation options offered by SPM2.
>
> I _haven't_ tried it with SPM5.
>
> Hope it is useful.
>
> Mark
>
> Ged Ridgway wrote:
>> Hi Siawoosh,
>>
>> Good question... there are no options for it, but if you change line
>> 242 of spm_defs.m:
>> dat = spm_sample_vol(V,d{:},1);
>> to have a number other than 1 at the end, you can get different
>> interpolation schemes. See the help for spm_sample_vol.
>>
>> Confusingly, spm_sample_vol seems to offer sinc or polynomial, but
not
>> b-spline -- I'm afraid I can't help there; maybe John will explain
that.
>>
>> Now I've just noticed you said spm2, and I'm looking at spm5, sorry!
>> Line 47 of Deformations/spm_applydef_ui.m looks equivalent...
>> img = spm_sample_vol(VI(i),y1,y2,y3,1);
>> and the same goes for spm_sample_vol as above.
>>
>> Best,
>> Ged.
>>
>>
>> Siawoosh Mohammadi wrote:
>>> hello world,
>>>
>>> a question about SPM2:
>>> within the deformation-toolbox there is the possibility to apply the
>>> deformation-field.
>>> is it also possible to write the resulting image with
>>> bspline-interpolation?
>>>
>>> thanks and bye bye
>>> siawoosh
>>>
>>> --
>>> Siawoosh Mohammadi
>>>
>>> Dept. of Neurology
>>> University of Muenster Phone: +49-251-8352061
>>> Albert-Schweitzer-Strasse 33 Fax: +49-251-8348181
>>> 48129 Muenster, Germany E-mail:
[log in to unmask]
>>>
>>>
>
>
>
------------------------------------------------------------------------
>
> function spm_applydef_ui(P,PT,interp)
> % Applies a deformation field to an image
> %
> % Changes made by Mark Daglish 04/11/19
> % Wanted to allow different interpolation levels so
> % 1: interp added to function call
> % 2: If no vargin then full gui with P (array of deformation fields)
> % PT (array of images to warp) and interp (level of
interpolation)
> % are required to be specified.
> % If P & PT are defined, but not interp, then assume someone is
expecting
> % John's original program and set interp=1 as default.
> % If P, PT & interp are specified then use them & skip GUI.
> % 3: Calls to spm_slice_vol and spm_sample_vol changed to include
> % interp variable
>
%_______________________________________________________________________
> % @(#)spm_applydef_ui.m 1.4 John Ashburner 04/03/24
>
> if nargin<3
> if nargin == 2
> interp=1;
> else
> n = spm_input('Number of subjects','+0', 'n', '1', 1)';
> for i=1:n
> P{i} =
spm_get(1,{'*y_*.img','noexpand'},['Select deformation field '
num2str(i)]);
> PT{i} = spm_get(Inf,'*.img',['Image(s) to warp
(' num2str(i) ')']);
> end
> % Option to change interpolation method added by Mark
Daglish 04/11/18
> interp = spm_input('Interpolation Method?','+1','m',...
> ['Nearest Neighbour|Trilinear
Interpolation|',...
> '2nd Degree B-spline|3rd Degree B-spline|4th
Degree B-spline|',...
> '5th Degree B-spline|6th Degree B-spline|7th
Degree B-spline'],...
> [0 1 2 3 4 5 6 7], 2);
>
> % --------------End of change------------
> end
> else
> n = length(P);
> if n ~=length(PT)
> error('Must have matching deformation / files list cell
arrays as inputs to spm_applydef_ui')
> end
> end
> spm_progress_bar('Init',n,'Applying deformations','subjects
completed');
> for i=1:length(P),
> Pi = [repmat([P{i} ','],3,1) num2str([1 2 3]')];
> % Change to include interpolation in call to spm_applydef
> spm_applydef(Pi,PT{i},interp);
> spm_progress_bar('Set',i);
> end;
> spm_progress_bar('Clear')
> return;
>
%_______________________________________________________________________
>
>
%_______________________________________________________________________
> function spm_applydef(VD,VI,interp)
> if ischar(VD), VD = spm_vol(VD); end;
> if ischar(VI), VI = spm_vol(VI); end;
> VO = VI;
> for i=1:length(VO),
> VO(i).fname = prepend(VO(i).fname,'w');
> VO(i).dim(1:3) = VD(1).dim(1:3);
> VO(i).mat = VD(1).mat;
> if ~isfield(VO,'descrip'), VO(i).descrip = ''; end;
> VO(i).descrip = ['warped ' VO(i).descrip];
> end;
> VO = spm_create_vol(VO);
> % Changed to include interp variable in calls to spm_slice_vol &
spm_sample_vol
> for p=1:VD(1).dim(3),
> M = spm_matrix([0 0 p]);
> x1 = spm_slice_vol(VD(1), M, VD(1).dim(1:2),interp);
> x2 = spm_slice_vol(VD(2), M, VD(1).dim(1:2),interp);
> x3 = spm_slice_vol(VD(3), M, VD(1).dim(1:2),interp);
> for i=1:length(VI),
> M = inv(VI(i).mat);
> y1 = M(1,1)*x1+M(1,2)*x2+M(1,3)*x3+M(1,4);
> y2 = M(2,1)*x1+M(2,2)*x2+M(2,3)*x3+M(2,4);
> y3 = M(3,1)*x1+M(3,2)*x2+M(3,3)*x3+M(3,4);
> img = spm_sample_vol(VI(i),y1,y2,y3,interp);
> VO(i) = spm_write_plane(VO(i),img,p);
> end;
> end;
> VO = spm_close_vol(VO);
> return;
>
%_______________________________________________________________________
>
>
%_______________________________________________________________________
> function out = prepend(in, pre)
> [pth,nme,ext,ver] = fileparts(in);
> out = fullfile(pth,[pre nme ext ver]);
> return;
>
%_______________________________________________________________________
|