Hi John,
The deformation field is contained in the 'iy' variable which is referenced near the top of that script snippet I put in my last email. Assuming that I did the conversion from mm-to-voxels correctly as you say, then the problem is probably in the creation of that deformation field?
As I said, I have a *sn.mat file that was generated when we did a non-linear normalisation of the diffusion-space image to MNI space. I loaded the *sn.mat and generated the deformation from Tr, then inverse-deformation field. This is where I'm most uncertain of my steps, because I based my code on other code that was based on spm_write_sn. If you could recommend any references that detail the steps of creating the deformation fields from Tr, I could really use them. Anyway, here is how I created the inverse 'iy', from start to finish.
%%%
load('-mat',Matname);
mat=VF.mat;
dim=VF.dim;
x=1:VG(1).dim(1);
y=1:VG(1).dim(2);
z=1:VG(1).dim(3);
BX=spm_dctmtx(VG(1).dim(1),size(Tr,1),x-1);
BY=spm_dctmtx(VG(1).dim(2),size(Tr,2),y-1);
BZ=spm_dctmtx(VG(1).dim(3),size(Tr,3),z-1);
[X,Y]=ndgrid(x,y);
y1 = single(0); y1(VG(1).dim(1),VG(1).dim(2),VG(1).dim(3)) = 0;
y2 = single(0); y2(VG(1).dim(1),VG(1).dim(2),VG(1).dim(3)) = 0;
y3 = single(0); y3(VG(1).dim(1),VG(1).dim(2),VG(1).dim(3)) = 0;
wM = VG(1).mat;
for j=1:length(z);
X1 = X + BX*get_2Dtrans(Tr(:,:,:,1),BZ,j)*BY';
Y1 = Y + BX*get_2Dtrans(Tr(:,:,:,2),BZ,j)*BY';
Z1 = z(j) + BX*get_2Dtrans(Tr(:,:,:,3),BZ,j)*BY';
y1(:,:,j) = single(wM(1,1)*X1 + wM(1,2)*Y1 + wM(1,3)*Z1 + wM(1,4));
y2(:,:,j) = single(wM(2,1)*X1 + wM(2,2)*Y1 + wM(2,3)*Z1 + wM(2,4));
y3(:,:,j) = single(wM(3,1)*X1 + wM(3,2)*Y1 + wM(3,3)*Z1 + wM(3,4));
end
disp(['Inverting the deformations field...']);
aM = Affine/VG(1).mat; aM(4,:) = [0 0 0 1];
[iy1,iy2,iy3] = spm_invdef(y1,y2,y3,VF.dim,aM,VG(1).mat);
iy=cat(5,iy1,iy2,iy3);
%%%%% Then for each point in my tractography path, I transformed a point C=[x y z] using
dC=squeeze(iy(C(1),C(2),C(3),1,:));
%%%%%
Much thanks,
Eve LoCastro
Research Programmer - IDEAL Lab
Radiology Department
Weill Cornell Medical College
515 E. 71st St S118
Tel: 212-746-1289
Fax: 212-746-4189
________________________________________
From: John Ashburner [[log in to unmask]]
Sent: Tuesday, May 15, 2012 8:08 AM
To: Eve M. LoCastro
Cc: [log in to unmask]
Subject: Re: [SPM] Deformation Point-Mapping Question
The snippet of MATLAB code seems to be for transforming one set of
coordinates to another. How did you use this to generate the image in
your email?
Bye for now,
-John
On 14 May 2012 17:00, Eve LoCastro <[log in to unmask]> wrote:
> Hello all,
>
> I have a set of tractography points that were externally calculated in the patient's DTI-space. My goal is to map the tracts into MNI space, and I have endeavored to do this by deformation-mapping the individual points. I am having a problem with the results, as there are strange, wavy voids appearing in the resultant mapping.
>
> I normalized the patient's diffusion-space ("s"-prefix) image to MNI space ("w"-prefix), generating a '*_sn.mat' file. I generated the 5-D inverse transform volume from the resultant Tr, and have been calculating the location of each s-point in w-space as follows:
>
> for l=1:size(sVoxPath,1)
> C=[sVoxPath(l,1) sVoxPath(l,2) sVoxPath(l,3)]; %C(x,y,z) is the diffusion coordinate in voxels
> dC=squeeze(iy(C(1),C(2),C(3),1,:)); %iy is the inverse-deformation
> N1=M1*[dC;1]; %M(i,:) are the rows of the inverse of the MNI-vox-to-coord transform
> N2=M2*[dC;1];
> N3=M3*[dC;1];
> wVoxPath(l,:)=[N1 N2 N3]; %Resulting N1, N2, N3 should be the C-coord in MNI voxels
> end
>
> My result appears to be in the right space, but with these wavy artifacts that are obviously wrong (see attached image). Is there some step I'm missing? Please let me know if you would like the details of how I calculated the deformation map.
>
> Much thanks,
> Eve LoCastro
> Research Programmer - IDEAL Lab
> Radiology Department
> Weill Cornell Medical College
> 515 E. 71st St S118
> Tel: 212-746-1289
> Fax: 212-746-4189
|