> The first problem caused by having 3D data is that loaddat doesn't
> load Ng (or Nf) because loops such as starting at line 221
> for k = 1:d(4)-1
I've now fixed that one by changing line 32 of spm_klaff.m to:
nd = min([df(4)+1,dg(4)]); % Use the first nd volumes.
> It turns out that for certain matrices, M, the values of x1, y1 or z1
> can be very close to but not quite > 1. This causes the subsequent
> lines (107-109)
> msk = x1>=1 & x1<=df(1) &...
> y1>=1 & y1<=df(2) &...
> z1>=1 & z1<=df(3);
> to generate an empty msk.
I don't think an empty mask should be a problem as there will be plenty of
other planes of data containing information. There may be a small loss of
accuracy, but it would make things go ever so slightly faster. Anyway, in my
changes to the code, I've wrapped the necessary lines between an "if
any(msk(:))" and "end" - just in case there are problems. MATLAB can be a
bit unpredictable in how it handles empty matrices. For example, try:
size([  ])
> Around line 45 it says [x,y ,zz] = ndgrid(1:dg(1),1:dg(2),0);
> This will make zz all 0's, so I don't understand why at line 49 it is
> added to z and if it really should be all 0's?
spm_bsplins expects arguments 2, 3 and 4 to all have the same dimensions. It
would crash if I just passed a scalar rather than an array.
> Messing around with all of this doesn't lead to optimum convergence of
> dM and the resulting warped volumes end up being shifted and tiny...
This would depend on how things were messed around with, but there was an
email to the list a few weeks ago where some wierd results were reported from
this routine. I haven't yet identified the cause of this problem. For the
affine registration, it is supposed to show a few numbers that indicate the
convergence. My attempt just produced:
Running 'Normalise to MNI Space'
** Affine registering "output" with MNI space **
1 5.66208 0.103395
2 3.98768 0.029183
3 0.846455 0.0124364
4 0.259187 0.0121146
5 0.0922449 0.0121154
6 0.0363161 0.0121065
7 0.015159 0.012108
8 0.00651621 0.0121074
9 0.00284269 0.0121076
10 0.00125002 0.0121075
11 0.000552058 0.0121075
12 0.000244923 0.0121075
The first column is the iteration number. The last column is the objective
function (KL-divergence), which is supposed to be minimised. Notice that
values can go slightly up as well as down (depending on the voxels included
in msk). The second column contains the sum of squares of the derivatives of
the objective function w.r.t. the parameters. This should approach zero at
All the best,