Hi,
On Thu, Aug 11, 2011 at 1:40 PM, Satrajit Ghosh <[log in to unmask]> wrote:
> hi,
>
> is there a quick way to get an inverse matrix for a coregistration transform
> and be able to apply it?
>
> essentially, all operations are within subject, but cross modal. i need to
> coregister from space A (modality 1) to space B (modality 2) and apply the
> transform to some images already in registration with A (i can do this
> easily with coregister). but then, i do something in space B, save a file
> and want to transform it back to space A.
Let's say you have A
a.img
a.hdr
We get the voxel to mm transform with:
>> a_orig_mat = spm_get_space('a.img');
You coregister it with B (where B is the target). Now a.hdr has
changed, and specifically
>> a_coreged_mat = spm_get_space('a.img'));
has changed, to be:
coreg * a_orig_mat
where `coreg` is the is 4x4 affine expressing the coregistration in
terms of mm in a_orig to mm of the mm space of 'b.img'.
To invert, you need the original space of a `a_orig_mat`.
>> coreg = a_coreg_mat * inv(a_orig_mat);
>> inv_coreg = inv(coreg);
To apply this to an image, say C, in the same space as B:
>> c_orig_mat = spm_get_space('c.img');
>> spm_get_space('c.img', inv_coreg * c_orig_mat);
This writes the header 'c.hdr' to contain the new .mat contents.
See you,
Matthew
|