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:

Proportional Font

LISTSERV Archives

LISTSERV Archives

SPM Home

SPM Home

SPM  August 2018

SPM August 2018

Options

Subscribe or Unsubscribe

Subscribe or Unsubscribe

Log In

Log In

Get Password

Get Password

Subject:

Re: Advice for SPM beginner on how to normalize structural volumes

From:

Guillaume Flandin <[log in to unmask]>

Reply-To:

Guillaume Flandin <[log in to unmask]>

Date:

Mon, 13 Aug 2018 12:42:42 +0100

Content-Type:

multipart/mixed

Parts/Attachments:

Parts/Attachments

text/plain (365 lines) , batch_normalised_mesh.m (11 lines)

Hi Jay,

Here is something that will work using the batch interface - see
attached file. It uses:
  SPM > Spatial > Segment
  SPM > Util > Rendering > Extract Surface
  SPM > Util > Deformations
The second module will call isosurface() and the third one spm_swarp().
Note that it uses the inverse deformation field.

Best regards,
Guillaume.


On 09/08/18 01:30, Dubb, Jay wrote:
> Hi Guillaume,
> 
> Thank you very much for your suggestion and sorry for the delayed
> response - I was trying to learn as much as I could about using SPM12
> before posting any other question. And yes the spm_swarp.m function that
> you pointed me to looks like exactly what I need: that is to use the
> deformation field to transform native coordinates to MNI space. But I
> must be doing something wrong because the output mesh that spm_swarp
> returns has about half the vertices equal to 0.
> 
> Looking at my processing below, would you have any idea what the problem
> could be? Also would greatly appreciate any example of correctly using
> spm_swarp or any other function that uses the deformation field to
> generate a warped mesh.
> 
> Here's what I do (again I only deal with structural NIFTI volumes, no
> fMRI's).
> 
>      T1.nii                     -->  Segmentation   -->  c1T1.nii
>      T1.nii, c1T1.nii     -->  Coregistration   -->  rT1.nii, rc1T1.nii
>      rT1.nii, rc1T1.nii  -->  Normalization   -->  wrT1.nii, wrc1T1.nii,
> y_rT1.nii
> 
> After this processing, I want to apply the deformation field y_rT1.nii
> to the subject's brain mesh to get the corresponding MNI coordinates.
> This is the code I use:
> 
>       %%%%% Finished running Segmentation, Coregistration,
> Normalization. Now apply the
>       %%%%% deformation field to the coregistered brain mesh
> 
>       % First generate brain mesh from coregistered structural brain volume
>       brain_nii = MRIread([subj_folder, '/rc1T1.nii']);
>       brain_mesh = isosurface(brain_nii.vol, 0.9);
> 
>       % isosurface flips x and y, so flip it back to be consistent with
> voxel space
>       brain_mesh.vertices = [brain_mesh.vertices(:,2),
> brain_mesh.vertices(:,1), brain_mesh.vertices(:,3)];
> 
>       % Generate warped mesh using spm_swarp. Use similar code as
> spm_deformations.m
>       % which also calls spm_swarp during normalization. Copied to here,
> from
>       % spm_deformations.m, the internal functions:
>       %
>       %    get_comp, get_job, get_def, get_idbbvox, get_idbbvox, and
> identity
>       %
>       % so we can mimic what spm_deformations does
>  
>        job{1}.def = {[subj_folder, '/y_rT1.nii']};
>        job{2}.idbbvox =
> matlabbatch{3}.spm.spatial.normalise.estwrite.woptions;
>        [def, T] = get_comp(job);
>        wbrain_mesh = spm_swarp(brain_mesh, def, T);
> 
>        % convert gifti to struct
>        wbrain_mesh_s.vertices  = wbrain_mesh.vertices;
>        wbrain_mesh_s.faces       = wbrain_mesh.faces;
> 
> 
> When this is done, I see that the number of vertices and faces in the
> original and warped meshes matches. But when I view random vertices in
> the warped mesh I see row after row of [0,0,0]. Also when I view the
> original mesh against the warped mesh in a figure, I see a very strange
> looking brain - only about a quarter to an 8th piece of the warped brain. 
> 
> Any help would be very appreciated. For reference I include below, the
> job parameters I used to create the output. 
> 
> Jay
> 
> ====================================================
>      spm('defaults','fmri');
>      spm_jobman('initcfg');
>      clear matlabbatch
> 
>       %%%%% Segmentation
>      matlabbatch{1}.spm.spatial.preproc.channel.vols = {[subj_folder,
> '/T1.nii,1']};
>      matlabbatch{1}.spm.spatial.preproc.channel.biasreg = 0.001;
>      matlabbatch{1}.spm.spatial.preproc.channel.biasfwhm = 60;
>      matlabbatch{1}.spm.spatial.preproc.channel.write = [0 0];
>      matlabbatch{1}.spm.spatial.preproc.tissue(1).tpm =
> {'c:\spm12\tpm\TPM.nii,1'};
>      matlabbatch{1}.spm.spatial.preproc.tissue(1).ngaus = 1;
>      matlabbatch{1}.spm.spatial.preproc.tissue(1).native = [1 0];
>  
>       % run segmentation separately rather than as part of one big job -
> for debugging purposes
>       spm_jobman('run',matlabbatch(1));
> 
>       %%%%% Coregistration
>       matlabbatch{2}.spm.spatial.coreg.estwrite.ref = {[mni_folder,
> '/mni152/T1.nii,1']};
>       matlabbatch{2}.spm.spatial.coreg.estwrite.source = {[subj_folder,
> '/T1.nii,1']};
>       matlabbatch{2}.spm.spatial.coreg.estwrite.other = {
>                                                                        
>                              [subj_folder, '/c1T1.nii,1']
>                                                                        
>                              [subj_folder, '/c2T1.nii,1']
>                                                                        
>                              [subj_folder, '/c3T1.nii,1']
>                                                                        
>                           };
>        matlabbatch{2}.spm.spatial.coreg.estwrite.eoptions.cost_fun = 'nmi';
>        matlabbatch{2}.spm.spatial.coreg.estwrite.eoptions.sep = [4 2];
>        matlabbatch{2}.spm.spatial.coreg.estwrite.eoptions.tol = [0.02
> 0.02 0.02 0.001 0.001 0.001 0.01 0.01 0.01 0.001 0.001 0.001];
>        matlabbatch{2}.spm.spatial.coreg.estwrite.eoptions.fwhm = [7 7];
>        matlabbatch{2}.spm.spatial.coreg.estwrite.roptions.interp = 4;
>        matlabbatch{2}.spm.spatial.coreg.estwrite.roptions.wrap = [0 0 0];
>        matlabbatch{2}.spm.spatial.coreg.estwrite.roptions.mask = 0;
>        matlabbatch{2}.spm.spatial.coreg.estwrite.roptions.prefix = 'r';
>  
>        % run coregistration separately rather as part of one big job -
> for debugging purposes
>        spm_jobman('run',matlabbatch(2));
>  
>  
>         %%%%% Normalization
>         matlabbatch{3}.spm.spatial.normalise.estwrite.subj.vol =
> {[subj_folder, '/rT1.nii,1']};
>         matlabbatch{3}.spm.spatial.normalise.estwrite.subj.resample = {
>                                                                        
>                                                       [subj_folder,
> '/rT1.nii,1']
>                                                                        
>                                                       [subj_folder,
> '/rc1T1.nii,1']
>                                                                        
>                                                    };
>         matlabbatch{3}.spm.spatial.normalise.estwrite.eoptions.biasreg =
> 0.0001;
>         matlabbatch{3}.spm.spatial.normalise.estwrite.eoptions.biasfwhm
> = 60;
>         matlabbatch{3}.spm.spatial.normalise.estwrite.eoptions.tpm =
> {'c:\spm12\tpm\TPM.nii']};
>         matlabbatch{3}.spm.spatial.normalise.estwrite.eoptions.affreg =
> 'mni';
>         matlabbatch{3}.spm.spatial.normalise.estwrite.eoptions.reg = [0
> 0.001 0.5 0.05 0.2];
>         matlabbatch{3}.spm.spatial.normalise.estwrite.eoptions.fwhm = 0;
>         matlabbatch{3}.spm.spatial.normalise.estwrite.eoptions.samp = 3;
>         matlabbatch{3}.spm.spatial.normalise.estwrite.woptions.bb =
> [-127 -127 -127
>                                                                        
>                                                    128 128 128];
>         matlabbatch{3}.spm.spatial.normalise.estwrite.woptions.vox = [1
> 1 1];
>         matlabbatch{3}.spm.spatial.normalise.estwrite.woptions.interp = 4;
>         matlabbatch{3}.spm.spatial.normalise.estwrite.woptions.prefix = 'w';
>    
>         % run normalization separately as part of one big job - for
> debugging purposes
>         spm_jobman('run',matlabbatch(3));
> 
> 
> ------------------------------------------------------------------------
> *From:* Guillaume Flandin <[log in to unmask]>
> *Sent:* Wednesday, August 1, 2018 5:20:02 AM
> *To:* Dubb, Jay
> *Cc:* [log in to unmask]
> *Subject:* Re: [SPM] Advice for SPM beginner on how to normalize
> structural volumes
>  
> Dear Jay,
> 
> Have a look at spm_mesh_transform.m (a basic wrapper above spm_swarp.m);
> the coordinates will have to be stored in a 'vertices' field of a struct.
> 
> Best regards,
> Guillaume.
> 
> 
> On 31/07/18 20:26, Dubb, Jay wrote:
>> 
>> Hi Tibor, 
>> 
>> 
>> Thanks for the links and tips. Now that I've read up on these topics and
>> played around a bit more with SPM, I have a more specific question:
>> 
>> 
>> I ran Normalization in SPM12 for my structural volume named rT1.nii and
>> got as output the files y_rT1.nii and wrT1.nii. I checked the
>> registration of the normalized subject volume (wrT1.nii) against the
>> MNI152 template using the SPM Check Reg and see that it looks accurate.
>> 
>> 
>> My question is, do you know how I would apply the output of
>> normalization in a Matlab script to the coordinates of the initial
>> subject volume rT1.nii, to calculate the corresponding MNI coordinates. 
>> 
>> 
>> Thanks again, 
>> 
>> Jay 
>> 
>> 
>> 
>> 
>> 
>> 
>> ------------------------------------------------------------------------
>> *From:* SPM (Statistical Parametric Mapping) <[log in to unmask]> on
>> behalf of Auer, Tibor <[log in to unmask]>
>> *Sent:* Tuesday, July 31, 2018 7:14 AM
>> *To:* [log in to unmask]
>> *Subject:* Re: [SPM] Advice for SPM beginner on how to normalize
>> structural volumes
>>  
>> 
>> Hi Jay,
>> 
>>  
>> 
>> Ad a.: I recommend you to read the corresponding section of the SPM
>> manual and/or the SPM book
>> (https://www.fil.ion.ucl.ac.uk/spm/doc/books/hbf2/). There also other
> HUMAN BRAIN FUNCTION 2nd EDITION - fil.ion.ucl.ac.uk
> <https://www.fil.ion.ucl.ac.uk/spm/doc/books/hbf2/>
> www.fil.ion.ucl.ac.uk
> Human Brain Function, 2nd edition. 2 nd EDITION. Section Editors. J
> Ashburner K Friston W Penny. PART II - IMAGING NEUROSCIENCE - THEORY AND
> ANALYSIS
> 
> 
> 
>> useful online materials. Se e.g. mine:
>> http://www.cubic.rhul.ac.uk/wiki/lib/exe/fetch.php?media=fmri:5_pre-processing.pdf(slide
>> 9 and onwards).
>> 
>>  
>> 
>> Ad b.: You can try mailing list archive. E.g. for DARTEL (you mentioned
>> non-linear transformations):
>> https://www.jiscmail.ac.uk/cgi-bin/webadmin?A2=spm;2d6e16b4.1202
>> 
>>  
>> 
>> Vale,
>> 
>> Tibor
>> 
>>  
>> 
>> *Auer, Tibor M.D. Ph.D.*
>> 
>> *Research Fellow in MRI*
>> 
>> *Department of Psychology*
>> 
>> Royal Holloway University of London
>> 
>> Egham Hill
>> 
>> Egham
>> 
>> TW20 0EX
>> 
>> United Kingdom
>> 
>> +44-1784-27-*6594*
>> 
>> [log in to unmask] <mailto:[log in to unmask]>
>> 
>>  
>> 
>>  
>> 
>> *From:*SPM (Statistical Parametric Mapping) [mailto:[log in to unmask]]
>> *On Behalf Of *Dubb, Jay
>> *Sent:* 30 July 2018 23:39
>> *To:* [log in to unmask]
>> *Subject:* [SPM] Advice for SPM beginner on how to normalize structural
>> volumes
>> 
>>  
>> 
>>  
>> 
>> Hello dear SPM users,
>> 
>>  
>> 
>> I am new to SPM.  I am looking for advice about some relatively simple
>> examples of how one could use the SPM12 batch script to convert
>> structural volume native coordinates, say T1.nii, to MNI space. My
>> MATLAB graphical application displays individual subjects' head
>> and brain in 3D in their native space. It allows users to hide the head
>> and click on any location on the brain. I want  to add the ability to
>> display the MNI152 coordinates which correspond to the selected
>> native cortical locations. (Even though it's a MATLAB application, it
>> has some parts which tie it to Windows, therefore I am not looking at
>> applications such as FSL and FNIRT, which are Linux-based.)
>> 
>>  
>> 
>> I was told that I have to do segmentation and then normalization. Maybe
>> coregistration as well, although unclear about that too.  Or can I do
>> ONLY the normalization step with T1.nii as input? 
>> 
>>  
>> 
>> My questions are: 
>> 
>>  
>> 
>> a) What steps are needed to do the MNI normalization for my purposes (I
>> only care about single subject structural NIFTI volumes, No fMRI)
>> 
>>  
>> 
>> b) How would one use the output of the normalization workflow in a batch
>> script to do the coordinate transformation to MNI? Since normalization
>> involves warping, and non-linear transformations, it's not as simple as
>> applying an affine 4x4 transformation matrix to my native coordinates
>> ... as far as I understand. 
>> 
>>  
>> 
>> Any advice would be greatly appreciated...
>> 
>>  
>> 
>> Jay 
>> 
>>  
>> 
>>  
>> 
> 
> -- 
> Guillaume Flandin, PhD
> Wellcome Centre for Human Neuroimaging
> University College London
> 12 Queen Square
> London WC1N 3BG

-- 
Guillaume Flandin, PhD
Wellcome Centre for Human Neuroimaging
University College London
12 Queen Square
London WC1N 3BG

Top of Message | Previous Page | Permalink

JiscMail Tools


RSS Feeds and Sharing


Advanced Options


Archives

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