JiscMail Logo
Email discussion lists for the UK Education and Research communities

Help for SPM Archives


SPM Archives

SPM Archives


SPM@JISCMAIL.AC.UK


View:

Message:

[

First

|

Previous

|

Next

|

Last

]

By Topic:

[

First

|

Previous

|

Next

|

Last

]

By Author:

[

First

|

Previous

|

Next

|

Last

]

Font:

Monospaced Font

LISTSERV Archives

LISTSERV Archives

SPM Home

SPM Home

SPM  October 2009

SPM October 2009

Options

Subscribe or Unsubscribe

Subscribe or Unsubscribe

Log In

Log In

Get Password

Get Password

Subject:

Re: [FSL] rmsdiff

From:

DRC SPM <[log in to unmask]>

Reply-To:

DRC SPM <[log in to unmask]>

Date:

Wed, 14 Oct 2009 08:43:38 +0100

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (134 lines)

Dear Sarah and Dianne,
(and FSL and SPM mailing lists, since it's a bit of a cross-over
question; sorry to those of you who read both!)

Starting with the easy bit... The reference volume is usually the
target of the registration, for FLIRT this is -ref, for SPM's Coreg
GUI it's "reference", but for the spm_coreg function (at the MATLAB
command line) it's VG. With non-rigid (though see below), for SPM's
normalise it's "template" , for the unified segmentation it's the
tissue probability maps (TPMs), and for DARTEL it's (any one of) the
group-wise average templates.

For converting rigid/affine matrices, I'm afraid it depends how you're
doing the registration in SPM. If you're calling spm_coreg directly,
then as described in the help, the output relates the voxel
coordinates in the images via:
  VF.mat\spm_matrix(x)*VG.mat
or in other words, M=spm_matrix(x) maps from target world/mm
coordinates to source world/mm coordinates. Note that VF.mat\blah
means inv(VF.mat)*blah, which maps from (source) world/mm coordinates
to source voxel coordinates.

You could then convert M to a FLIRT matrix (from source to target
"scaled" coordinates) using worldmat2flirtmat in the package of
snippets here:
  http://www.nitrc.org/snippet/detail.php?type=package&id=1

If you run Coreg from the SPM GUI, things are a bit more complicated,
since it modifies the voxel-world mapping in the source image, VF.mat,
in-place. Noting that VF.mat\M*VG.mat can be written
inv(inv(M)*VF.mat)*VG.mat, we see that VF.mat gets premultiplied by
the inverse of the output from spm_coreg (this happens in either
spm8/config/spm_run_coreg_estimate.m or spm5/spm_config_coreg.m --
search for spm_get_space, which is the function used to get/set the
transformation in the NIfTI headers).

Two things to note about this. First, Sarah, if you've coregistered
one image twice (to two different targets, or using different
parameters) then unless you've done the registrations on two different
copies of the original source image, the second coreg will have
started from where the first finished, which probably isn't what you
want, if you're trying to compare them fairly. Second, you need to
have kept a copy of the original source image (or its VF.mat) before
the registration to recover the matrix M from the result after the
registration, if you want to convert this for use with rmsdiff. You
could then do:
  after = spm_get_space('after.nii')
  before = spm_get_space('before.nii')
  M = before / after % or before*inv(after)
You could then proceed as above.

If you're doing non-rigid (non-affine) spatial normalisation, then you
can't convert to a matrix, and probably can't use FSL's rmsdiff
(though FSL might have an equivalent for displacement fields... I'm
not sure...). Probably the easiest thing in that case would be to
compute RMS differences yourself in MATLAB/SPM. You should be able to
convert blah_sn.mat files (or blah_seg_sn.mat from unified
segmentation, and also u_blah flow fields from DARTEL) to deformation
fields (y_blah) using the Deformations utility. The y_ files are
five-dimensional NIfTI images with dimensions [X Y Z 1 3], where X, Y
and Z are the numbers of voxels in these dimensions of the target
image, and the three components in the fifth dimension (the fourth was
reserved for time) are the x, y, and z coordinates of where each
target voxel maps to in source world/mm space. You can therefore
compare two different mappings (to the same target; things will be
more complicated if you wanted to compare mappings to two different
targets...) by directly computing the RMS difference between these
fields. E.g. the following might work, though I haven't tested it for
typos etc...
  A = nifti('y_a.nii');
  B = nifti('y_b.nii');
  D = A.dat(:, :, :, 1, :) - B.dat(:, :, :, 1, :);
  % If the above throws an error, check y_a and y_b relate to the same target
  err2 = sum(D.^2, 5); % sum over 5th dimension
  % err2 is a three-dimensional image of squared errors (in mm^2)
  rms = sqrt(mean(err2(:)))

This would also let you compute maximum error in mm, etc. etc.
  max(sqrt(err2(:)))
  hist(sqrt(err2(:))) % plot histogram

Note that the above mean and max are over all voxels in the target; it
might make more sense to use only voxels within a mask (defined over
the same space as the target image). E.g. if your y_ deformation comes
from unified segmentation, you should be able to do something like:
  G = spm_vol(fullfile(spm('dir'), 'TPM', 'grey.nii'));
  G = spm_read_vols(G) > 0.5;
then e.g.
  rms = sqrt(mean(err2(G)))
to compute RMS error over just the voxels with more than 50% (prior)
probability of being GM.

I hope (some of?!) that helps!

Ged


2009/10/5 Dianne Patterson <[log in to unmask]>:
> Dear Group,
> Has anyone answered this question? What is the relationship between spm
> registration matrices and fsl registration matrices?
> I'm looking forward to hearing more about this.
> -Dianne
>
> On Fri, Oct 2, 2009 at 3:35 PM, Sarah Andersen <[log in to unmask]>
> wrote:
>>
>> Dear Group,
>> I just learned about the rmsdiff utility and would really like to use it
>> to compare two
>> different normalizations of the same image. From the usage it seems that I
>> need to input
>> the two matrix files, one from each of the normalizations. However, I did
>> these
>> normalizations in SPM and FSL doesn't seem to recognize the SPM output
>> matrix. Is there a
>> way to convert the SPM matrix into something that FSL can read?
>> Also is the reference volume the initial brain before either of the
>> normalizations?
>>
>> Thanks!
>> Sarah
>>
>
>
>
> --
> Dianne Patterson, Ph.D.
> [log in to unmask]
> University of Arizona
> SLHS 328
> 621-5105
>

Top of Message | Previous Page | Permalink

JiscMail Tools


RSS Feeds and Sharing


Advanced Options


Archives

May 2024
April 2024
March 2024
February 2024
January 2024
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007
2006
2005
2004
2003
2002
2001
2000
1999
1998


JiscMail is a Jisc service.

View our service policies at https://www.jiscmail.ac.uk/policyandsecurity/ and Jisc's privacy policy at https://www.jisc.ac.uk/website/privacy-notice

For help and support help@jisc.ac.uk

Secured by F-Secure Anti-Virus CataList Email List Search Powered by the LISTSERV Email List Manager