Hi Mark,
On Jul 29, 2009, at 3:06 AM, Mark Jenkinson wrote:
> Hi,
>
> I don't know why you are using 0 for the last entry in (x,y,z,0) -
> it should be (x,y,z,1) and
> it is this in img2imgcoord and all other calls in FSL.
Okay, you're right, I checked this again. BTW, img2imgcoord prints
the last set of coordinates twice (minor bug?).
> Apart from that, what you have written makes sense and describes
> what is done in
> applyxfm4D or any other FSL tool like FLIRT. However, because you
> are trying
> to use this in matlab, with a volume that is cropped and another
> function (tformarray)
> then there are several things which may be going wrong. Firstly, be
> aware that all of
> the FSL coordinate conventions are like nifti - they start at 0 -
> whereas in matlab
> will start at 1. Also, be careful that you are giving it the matrix
> in the right direction
> (FLIRT stores a mapping *from* input *to* reference space, but your
> matlab function
> may want the opposite). In addition, be careful whether you need to
> give it a mapping
> between voxel coordinates or between mm coordinates.
>
> The qform is not used at all by FSL programs for spatial resampling
> *except* to check
> for radiological/neurological storage (former has negative
> determinant, the latter has
> positive determinant).
The transformation matrix must assume the origin is (0,0,0). But when
I crop the volume, the origin is now somewhere else, and so if I
attempt to apply the original transformation to the cropped volume, I
will get the wrong answer, right? (because the rotations are no longer
around the correct point)
So I've been thinking that I should subtract the offsets (translate)
then apply the flirt transformation, then add the offsets back again.
Hence, I should use the matrix you call D (which includes the offset
translations) rather than S (which includes only the voxel scaling).
> It isn't easy to convert between conventions for spatial coordinates
> and coordinate
> transformations - I know because I've had to do this in the past and
> it is painful.
> Can you get the correct answers for the actual coordinate locations
> (not resampling
> of images) between the matlab and fsl representations? For example,
> using img2imgcoord
> and matrix maths in matlab? If so, then it is probably just a
> question of working out
> what tformarray requires - and I'm not familiar with this so I
> cannot help.
Yes, img2imgcoord is computing inv(S) * A * S on zero-based voxel
coordinates, I can replicate that, it is just the offsets that are
giving trouble, I think.
keith
|