# Dilating of brain mask and some other general queries

**URL:** <https://community.mrtrix.org/t/dilating-of-brain-mask-and-some-other-general-queries/1304>\
**Category:** Uncategorized\
**Tags:** connectomics, tractography\
**Created:** [November 13, 2017, 6:29am UTC](https://community.mrtrix.org/t/dilating-of-brain-mask-and-some-other-general-queries/1304 "2017-11-13T06:29:07Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![Antonin\_Skoch](https://community.mrtrix.org/user_avatar/community.mrtrix.org/antonin_skoch/32/358_2.png) [@Antonin\_Skoch](https://community.mrtrix.org/u/Antonin_Skoch)\
**Post date:** [November 21, 2017, 10:02pm UTC](https://community.mrtrix.org/t/dilating-of-brain-mask-and-some-other-general-queries/1304/10 "2017-11-21T22:02:20Z")

</div>

Dear @Michiko,

I am working with HCP pipelines, but I cannot give answer specific to HCP data since I am not working with them (probably the dwi and structural HCP data are already in register?).

But generally, you have to assure that the structural and diffusion data are in register. This, however, does not mean that their voxel size has to be identical. Registering and regridding (reslicing) are two distinct things. You can bring the data to common coordinate systems without reslicing by adjusting their vox2RAS matrix in image header.

Registering structural to dwi (without reslicing structural, only modifying vox2ras matrix) I would do as follows:

Extract b=0 images and averaging them:  
`dwiextract -bzero dwi.mif - | mrmath - mean -axis 3 dwi_b0_mean.nii.gz`

Register dwi to structural:  
`bbregister --s $subject_id --mov dwi_b0_mean.nii.gz --init-coreg --lta dwi_b0_mean2fs.lta --dti`

For `5ttgen` I personally use `norm.mgz`, optionally with refined skullstrip by masking by `PreFreeSurfer` brain mask (maybe such masking is not necessary with HCP data)

`mri_mask $SUBJECTS_DIR/$subject_id/mri/norm.mgz ${hcp_rootdir}/${subject_ID}/T1w/T1w_acpc_brain_mask.nii.gz norm_preFS_brainmasked.nii.gz`

Getting subject’s `norm.mgz` in register to dwi (without reslicing)  
`mri_vol2vol --mov norm_preFS_brainmasked.nii.gz --targ dwi_b0_mean.nii.gz --lta-inv dwi_b0_mean2fs.lta --o norm2dwi.mgz --no-resample`

A note: The structural `PreFreeSurfer` data are AC-PC aligned, if the same is not applied for dwi, then there is optional step to bring dwi to AC-PC alignment before running `bbregister` to avoid possible failure in registration. There should be `acpc.mat` file in the HCP data directory which can be used for that. But then the steps are more complex.

A note 2: I personally currently prefer (maybe in contrast to common recommendations, I would appreciate a comment from other experts on this!) to do opposite, i.e. register dwi to structural mainly for following reason:

The structural data processed by HCP pipeline are AC-PC aligned. This is advantageous for all steps which require registration to MNI since the registration have good initial conditions. This truthfully matters for `FSL-first` (as part of `5ttgen` and `labelsgmfix`), where I found that changing initial head position can have profound effect on subcortical segmentation result.  
I think that the only pitfall in (rigid body!) transforming dwi data after they have been preprocessed by `dwipreproc`, is to pay attention to rotate your `.bvec` as well. However, when using `mif` format with dwi data, you no longer have to worry about it since `mrtransform` does it seamlessly.  
You could also do `5ttgen` in AC-PC aligned space and transform to dwi space resulting 5tt image (and also FreeSurfer parcellation image after `labelsgmfix`) but this seems to me less convenient.

Antonin

---

_[View the full topic](https://community.mrtrix.org/t/dilating-of-brain-mask-and-some-other-general-queries/1304)._
