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
|