Back to the main page.

Bug 3228 - ft_volumesegment: implement dartel as an alternative way for segmentation

Status NEW
Reported 2017-01-03 07:48:00 +0100
Modified 2017-05-14 11:32:38 +0200
Product: FieldTrip
Component: core
Version: unspecified
Hardware: PC
Operating System: Mac OS
Importance: P5 normal
Assigned to:
URL:
Tags:
Depends on: 2793
Blocks: 3255
See also: http://bugzilla.fieldtriptoolbox.org/show_bug.cgi?id=3255

Jan-Mathijs Schoffelen - 2017-01-03 07:48:54 +0100

as discussed with Bruno at Biomag. He has code to do this, which can probably be easily incorporated.


Jan-Mathijs Schoffelen - 2017-01-25 08:43:46 +0100

Hi, please bear with me, this is the first time I work on bugzilla and I am sure I won't contribute in the right format. I hope this helps anyway. I have used SPM12 quite a bit in the ft pipelines I developed. In the last iteration I am using Dartel-based normalization of native-space contrasts computed in native grids. Here I am giving the procedures for doing MNI grids based on the new segmentation in SPM, and also the procedures for doing the Dartel-based analysis (big picture approach). The code below for calling SPM routines is based on the batch system (need to dig the actual functions, and quite a few must be common to SPM8). 1. AC-center the anatomical to improve the segmentation. M=eye(4); M(1:3,end)=-AC; %AC is AC location in mm, [3,1] vector batch.spm.util.reorient.transform.transM = M; %run the batch. 2. use the new segmentation to extract the TPMs. The grey-matter TPM will be used to create the volume conduction model. batch: batch.spm.spatial.preproc requires TPM.nii in spmdir/tpm 3. MNI grid approach: estimate normalization from AC-centered native-space anatomical to MNI: batch.spm.tools.oldnorm.est 4. MNI grid approach: MNI normalize subject-specific grey-matter TPMs batch.spm.tools.oldnorm.write 5. MNI grid approach: average MNI-normalized grey-matter TPMs, and eventually exclude regions based on MNI atlases (e.g., AAL, although lately I prefer the Neuromorphometrics atlas in spm12/tmp) cfg=[]; cfg.grid.resolution=resolution; cfg.mri=mri; %group-average MNI grey TPM with non-interesting regions set to 0 cfg.threshold=0.25;% cfg.smooth=0; groupgrid=ft_prepare_sourcemodel(cfg); 6. various alignment steps 7. MNI grid approach: prepare volume conduction and source models using the new segmentation clear seg seg.gray=Gray; %spm_read_vol('c1acs.nii'); %c1 from ac-centered anatomical seg.white=White; %spm_read_vol('c2acs.nii'); seg.csf=CSF; %spm_read_vol('c3acs.nii'); seg.dim=MRI_HeadShapes.dim; %MRI_HeadShapes is the AC anatomical aligned to %digitized headshape seg.transform=MRI_HeadShapes.transform; seg.coordsys=MRI_HeadShapes.coordsys; seg.unit=MRI_HeadShapes.unit; cfg=[]; cfg.output='brain'; %create brain mask from segmentation seg=ft_volumesegment(cfg,seg); %not sure why I do this and the following three seg.gray=Gray; seg.white=White; seg.csf=CSF; cfg=[]; cfg.method='singleshell'; vol=ft_prepare_headmodel(cfg,seg); cfg = []; cfg.grid.warpmni = 'yes'; cfg.grid.template = groupgrid; cfg.grid.nonlinear = 'yes'; cfg.mri = seg; grid = ft_prepare_sourcemodel(cfg); The Dartel-based approach is much more involved! 1. ac-center native-space anatomicals; 2. segment ac-centered anatomicals; 3. create Dartel template using the anatomical segmentations at 2. Note, the stereotaxic space is specific to the group of participants. Further steps are required to move to/from MNI: batch.spm.tools.dartel.warp 4. normalize something from native to MNI through Dartel to estimate the Dartel-to-MNI transformation (e.g., participant-specific grey-matter TPMs): batch.spm.tools.dartel.mni_norm 5. normalize the Dartel template to MNI for eventual visualization and sanity checks: !cp -fv Template_6.nii Template_6_MNI.nii %Template_6.nii is the Dartel template load Template_6_2mni.mat %contains mni structure with Dartel-to-MNI transforms M = mni.affine; P='Template_6_MNI.nii'; Nii = nifti(P); Nii.mat = M; Nii.mat_intent = 4; create(Nii); %note, this changes the header not the data, so voxels are equispaced in Dartel not MNI space 6. transform atlases to Dartel space (here example based on aal_for_spm12 http://www.gin.cnrs.fr/AAL) eval(['!cp -fv AAL.nii AAL_Dartel.nii']) infile='AAL_Dartel.nii'; M1=spm_vol(infile); M1=M1.mat; M2=spm_vol([darteldir,'Template_6.nii,1']); M2=M2.mat; load([darteldir,'Template_6_2mni.mat']) M3 = mni.affine; M=M2*(M3\M1); P=infile; Nii = nifti(P); Nii.mat = M; Nii.mat_intent = 4; create(Nii); %now AAL_Dartel header is squeezed to Dartel space The next step is to resize bounding box and voxel size of the Dartel-normalized atlas so that it corresponds to what in the Dartel template: vtarg=spm_vol([maskdir,'Template_6.nii,1']); resize_img_BLG_nearNeighb('AAL_Dartel.nii',... %will attach this function later nan(1,3), nan(2,3), 0,vtarg.mat,vtarg.dim) %resize atlas to dartel template 'rAAL_Dartel.nii' can now be used for label-based removal of uninteresting regions from the Dartel-space grey-matter TPM 7. transform the Dartel-space TPM with uninteresting regions set to 0 from Dartel to native space batch.spm.tools.dartel.crt_iwarped batch.spm.tools.dartel.crt_iwarped.interp = 7; and set to a binary mask. 8. prepare native-space grids with specific resolution maskforgridfn=fn_for_native-space_mask computed at 7. targetvoxdim=in_mm; BB=nan(2,3); %if nans it uses bounding box of original volume resize_img_BLG_nearNeighb(maskforgridfn, targetvoxdim, BB, 1); vm=spm_vol(['r',maskforgridfn]); [Mask,XYZ]=spm_read_vols(vm); Mask=Mask(:)==1; cfg=[]; cfg.grid.pos =XYZ'/10;% = N*3 matrix with position of each source cfg.grid.inside =Mask; cfg.grid.dim =vm.dim;% cfg.unit='cm'; grid=ft_prepare_sourcemodel(cfg); 9. the forward model is computed as above. Now we need to compute the leadfields for the native-space grid. Before doing so, we transform the positions so that they include the alignment of the native-space anatomical to the digitized headshape. vgridmask=spm_vol((['r',maskforgridfn]); %the native-space grid mask at 7. Mgridmask=vgridmask.mat; vanat=spm_vol(anatfn); %the ac-centered anatomical for this subject Manat=vanat.mat; Mheadshapes=MRI_HeadShapes.transformorig; %form MRI-to-headshape alignment M1=Mgridmask; M2=Mheadshapes; M3=Manat; dim=grid.dim; %native-space grid from 8. [X,Y,Z] = ndgrid(1:dim(1), 1:dim(2), 1:dim(3)); posvox=[X(:) Y(:) Z(:)]; M=M2*inv(M3)*M1; grid.pos = ft_warp_apply(M,posvox)/10; Now we can compute leadfields using grid 10. when done with our native-space analyses we can finally dartel-normalize the contrasts/encoding/whatever measures of interest from native to group space. Note, this also uses a smoothing of the dartel-normalized images, which boosts SNR further than what already done by the improved Dartel-based alignment of anatomies. We have two options here. 10.a. we Dartel-normalize native-space stuff then smooth batch.spm.tools.dartel.crt_warped %dartel normalize THEN batch.spm.spatial.smooth %smooth 10.b. directly normalize to MNI (includes a smoothing step): batch.spm.tools.dartel.mni_norm The SPM community prefers 10.a. Note that with this option the Dartel normalization is slower than with option 10.b. Also, 10.a. produces volumes with the same resolution of the Dartel template, which should be overkill for MEG. Ideally, one would resample the output of 10.a. to a target resolution and find out how 10.a. can be sped up.


Jan-Mathijs Schoffelen - 2017-01-25 08:44:29 +0100

@comment 1: JM copied this over from bug 2793. Thanks Bruno for the documentation. I suggest to move it into this bug, because I think it's more appropriate to document it here :o).


Bruno L. Giordano - 2017-01-25 09:14:07 +0100

(In reply to Jan-Mathijs Schoffelen from comment #2) :-) Perhaps a large chunk of the dartel functionality should extend ft_prepare_headmodel rather than ft_volumesegment. In ft_prepare_headmodel, one could also include the atlas-based approach for eliminating structures based on labels in MNI atlases. For the dartel-based pipeline, ft_volumesegment should just include the new SPM12 default segmentation as an option (should be "unified segmentation", called "new segmentation" in SPM8). One additional function might also be required - ft_darteltemplate - to put together information from different experiment participants and prepare the dartel template. The dartel-based normalization could finally extend ft_volumenormalise In the grand scheme, we should also consider how this should be integrated with the stats functions. One thought about this is that the quite high overhead for dartel normalisation might make permutation-based group analyses quite difficult (I am sticking to parametric stats, for the moment). It should be possible to bring down this overhead through code hacking. Check e.g., slide 28 of https://www.tnu.ethz.ch/fileadmin/user_upload/teaching/SPM2016/Ridgway2016_SPMZurich_VBM.pdf to have a glimpse of the difference between traditional group-level normalization (template 0), and dartel-based normalization (template 6). What do you think?


Arjen Stolk - 2017-05-06 06:13:00 +0200

(In reply to Bruno L. Giordano from comment #3) Hi gents, Any idea what the timeline of this endeavor may be? Working with iEEG data, normalization of electrode positions remains an ongoing battle. The sample sizes are typically small and the atlases play an important role for selecting electrodes/areas of interest, hence it matters whether each electrode ends up. Currently, nonlinear warping with the default settings of spm8 (in ft_volumenormalize) doesnt provide reliable results, in worst case scenarios depth electrodes ending up outside the brain. We're currently in the process of wrapping and writing up an iEEG pipeline, in which we illustrate and cite the normalization techniques currently supported by fieldtrip through spm. It would be great if we could use this occasion to demonstrate and advertise the dartel technique. If it could be implemented in the coming few weeks or so, I could still add it. Best, Arjen


Jan-Mathijs Schoffelen - 2017-05-07 12:18:51 +0200

I don't think it is realistic that it will be added smoothly anytime soon. I have managed to strip the ugly example code in spm (getting rid of the batch manager etc), to get a DARTEL based normalization. Yet I am not sure so much what the advantage of this is beyond the most recent improvement (using the new-style segmentation). Bruno clearly has a good opinion about the benefits for his projects (and has hands on experience), but the extent to which this generalizes to the general FT-population, and whether it is worth the hassle is still unclear to me.


Arjen Stolk - 2017-05-13 09:26:34 +0200

These things indeed require a lot of fiddling, judging from my limited experiences with getting SPM12's affreg implemented. At the same time, it may be worth the effort if dartel produces reliable results. What's your take on how dartel stacks up to the other coreg procedures out there, Bruno?


Bruno L. Giordano - 2017-05-13 12:36:05 +0200

Created attachment 840 Dartel iterations Hi, I find going a Dartel-based pipeline much preferable for multiple reasons: 1. as you can see from the attached image, the spatial specificity of the anatomical template is much higher, implying better realignment of individuals, and more accurate anatomical labeling of group results (e.g., it seems to be the current SPM method of choice for VBM). One could reasonably object to these being important for MEG, given the high spatial blur of sources. This question is obviously empirical. See point 3. 2. Dartel MEG source analyses rely on projection grids that are isotropic in native space but not in group space. The traditional FT approach relies on projection grids that are isotropic in group space but not in native space. This difference is critical for MVPA searchlight analyses, perhaps even more so for the multimodal fMRI/MEG project for which I developed the Dartel pipeline. Indeed, few reviewers would likely accept MVPA of fMRI on non-isotropic native "grids". 3. The Dartel MEG pipeline relies on spatial smoothing of native-space "contrast" maps (e.g., MEG power, or RSA correlations in my case). I might be wrong, but with the MNI grid approach smoothing is usually not implemented. Smoothing of single subject maps prior to group analysis acknowledges imperfections in the normalizations. More importantly, spatial blur is reasonably expected to boost the power of group analyses. This corresponds to my experience. Obviously, what I am saying is that Dartel is expected to be beneficial because it improves the anatomical specificity of the template while decreasing that of functional results ;-) The Dartel pipeline is obviously much more involved and requires more steps than the traditional MNI pipeline. I would love to have the time right now to work on including it in the FT distribution, but at the moment I can't do much more than sharing commented code snippets. It would probably be a good idea to compare common statistics such as MEG power in the two pipelines before investing more time on this. This would be easy for me, but it could possibly happen only in e.g., July. Bruno


Arjen Stolk - 2017-05-14 06:28:30 +0200

Thanks, Bruno, for this overview. "1. as you can see from the attached image, the spatial specificity of the anatomical template is much higher, implying better realignment of individuals, and more accurate anatomical labeling of group results (e.g., it seems to be the current SPM method of choice for VBM). One could reasonably object to these being important for MEG, given the high spatial blur of sources. This question is obviously empirical. See point 3." - The template on the right looks way more crisp than the one on the left indeed. This anatomical precision would certainly be important for mapping over iEEG data, if not just for MEG. It's not clear to me how or why the dartel technique affords, or maybe causes, these anatomically more realistic template brains. Forgive my ignorance in this matter, but does the '6th iteration' here also imply that dartel is somehow also more efficient at it than other techniques? - Another recent observation with iEEG data (looking at single-subject electrode locations seems a good way for exposing shortcomings) is that electrodes sometimes are entirely off in the template brains. I can't really tell whether that is due to the template used (it seems to matter in some instances) or the algorithm itself. What is an issue though is that the quality of the scans are occasionally so-so, for instance in the case of a 'post-implant scan' (i.e. with electrode-related noise) or a contrast scan. Do you happen to have any idea whether dartel also disproportionally outperforms other techniques with inferior scan quality, or does it maybe become of an issue even? "The Dartel pipeline is obviously much more involved and requires more steps than the traditional MNI pipeline. I would love to have the time right now to work on including it in the FT distribution, but at the moment I can't do much more than sharing commented code snippets. It would probably be a good idea to compare common statistics such as MEG power in the two pipelines before investing more time on this. This would be easy for me, but it could possibly happen only in e.g., July." - It seems the implementation will stand or fall with your effort and expertise. I would be grateful for a method that seems to have the potential to boost both MEG and iEEG group-based analysis, and could provide help in the form of testing the code out on several iEEG datasets (e.g. comparing electrode positions in single subject space with template space).


Bruno L. Giordano - 2017-05-14 11:32:38 +0200

(In reply to Arjen Stolk from comment #8) It's simply a much better volumetric alignment method that relies on much more complex methods ;-) https://www.ncbi.nlm.nih.gov/pubmed/17761438 6th iteration is the 6th iteration of the alignment process. The template on the left was the 0th iteration. Dartel can potentially be used to create special templates (e.g., lesions) because it does not rely on external atlases when creating a template truly specific to your group of subjects. Perhaps if you have implant artifacts you can mask out roughly the same problematic region from all anatomicals. There should be similar examples in the literature/online. I have given Jan-Mathijs quite a few commented code snippets. Perhaps you can check them in the coming weeks? Bruno