At each point in the volumes, you get the x, y and z coordinate - one
from each volume. These coordinates are in mm, so if you want the
location in some image volume, you'll need to convert from the mm
coordinates to voxel indices. Note that you could have coregistered
images of the same subject that have different orientations,
dimensions etc. Each of those images would have different
voxel-to-world mappings.
Reading the voxel-to-world mapping from an image's header can be done by:
M=spm_get_space('filename.img');
This M maps from voxel indices to mm coordinates. You want the inverse of this:
iM = inv(M);
Then you can convert your mm coordinates into indices by:
i = iM(1,1)*x + iM(1,2)*y + iM(1,3)*z + iM(1,4);
j = iM(2,1)*x + iM(2,2)*y + iM(2,3)*z + iM(2,4);
k = iM(3,1)*x + iM(3,2)*y + iM(3,3)*z + iM(3,4);
In fact, you could do the whole lot at once by first reading all the
data into x,y,z:
Nii = nifti('y_filename.nii');
x = Nii.dat(:,:,:,1,1);
y = Nii.dat(:,:,:,1,2);
z = Nii.dat(:,:,:,1,3);
and then doing the matrix multiplication:
i = iM(1,1)*x + iM(1,2)*y + iM(1,3)*z + iM(1,4);
j = iM(2,1)*x + iM(2,2)*y + iM(2,3)*z + iM(2,4);
k = iM(3,1)*x + iM(3,2)*y + iM(3,3)*z + iM(3,4);
Best regards,
-John
On 7 June 2011 15:57, Yonatan Dinai <[log in to unmask]> wrote:
> John,
>
> Thanks for your reply, it seems to be exactly what I'm looking for.
> I'm having diffuculties though using either this or what Michael
> suggested (probably because of my lack of experience with analyse/nii
> and SPM in general...
>
> When I use normalization I get a warped version of my source image
> which is in good alignment with the reference
> (I checked that with spm_check_registration(images))
> However, the output matrix size is not the same size as the reference
> (and that's why I can't use Michael's approach)
> When I use the deformation tool (using a parameters file saved in a
> normalization process) I get 3 3D matrices, the same size as the
> reference, but I'm having troubles interperating the results...
>
> So any suggestions to what I'm doing wrong will be very much appreciated
>
> Thanks again,
> Yonatan
>
> On Mon, Jun 6, 2011 at 10:24 AM, John Ashburner <[log in to unmask]> wrote:
>> You could try the Deformations utility. This will write out a y_*
>> image (containing three volumes, [:,:,1,1], [:,:,1,2] and [:,:,1,3])
>> that encodes the mapping. You'll need to account for voxel-to-world
>> transforms in image headers to make use of it though, as the mapping
>> is saved in mm coordinates. The code is in spm_defs.m.
>>
>> Best regards,
>> -John
>>
>> On 5 June 2011 05:49, Yonatan Dinai <[log in to unmask]> wrote:
>>> Hello all,
>>>
>>> I've used the "normalize" function of SPM, and was able to warp two
>>> volumes succesfully.
>>>
>>> I would now like to use the output parameters of the normalization
>>> process - the 4x4 matrix of the affine transformation & the 4D matrix
>>> of the DCT coefficients to transform an input point (X,Y,Z in the
>>> source volume) into it's mapped point in the reference coordinates?
>>>
>>> Does anybody has a code the computes that transformation? Is there
>>> such a function on SPM? If not, I would be happy to hear of any fast
>>> way to compute such a transformation.
>>>
>>> Thanks a lot,
>>>
>>> Yonatan
>>>
>>
>
|