# DWI to T1w alignment, but poor effect

**URL:** https://community.mrtrix.org/t/dwi-to-t1w-alignment-but-poor-effect/6051
**Category:** Uncategorized
**Created:** [September 19, 2022, 12:54pm UTC](https://community.mrtrix.org/t/dwi-to-t1w-alignment-but-poor-effect/6051 "2022-09-19T12:54:32Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![hyting](https://community.mrtrix.org/letter_avatar_proxy/v4/letter/h/ed655f/32.png) [@hyting](https://community.mrtrix.org/u/hyting)
#### Post date: [September 19, 2022, 12:54pm UTC](https://community.mrtrix.org/t/dwi-to-t1w-alignment-but-poor-effect/6051/1 "2022-09-19T12:54:32Z")

</div>

HI,  
After the motion and distortion correction, I conducted the DTI to T1w alignment with the following lines.

```auto
# motion and distortion correction
dwifslpreproc degibbs.mif geomcorr2.mif -rpe_none -pe_dir PA -json_import "$dti".json -eddy_options " --data_is_shelled --slm=linear --niter=5"

# prepare for alignment to T1w
# extract mean_b0
dwiextract geomcorr2.mif - -bzero | mrmath - mean mean_b0.nii -axis 3
flirt.fsl -dof 6 -cost normmi -ref "$t1w".nii.gz -in mean_b0.nii -omat T_fsl.txt
transformconvert T_fsl.txt mean_b0.nii "$t1w".nii.gz flirt_import T_DWI2T1.txt
mrtransform -linear T_DWI2T1.txt geomcorr2.mif align.mif

```

and all these commands works well, but then when I overlapped the align.mif on the top of the T1w, it works badly (see below).

 ![alignment_effect](https://community.mrtrix.org/uploads/default/original/2X/3/3cb8cff491b41421fd5616086ab724a9a7af4b30.png)

even worse than before alignment (ie. overlapped the geomcorr2.mif on the top of the T1w, see below)

 ![before_alignment](https://community.mrtrix.org/uploads/default/original/2X/0/06bf73347bc7106f6eccc56ccb3cc52bc44afd83.png)

**I wonder that what cause this phenomenon? Is there any problem with my lines?**

Thank you in advance!!

---

<div class="post-metadata">

### Author: ![NicDC](https://community.mrtrix.org/user_avatar/community.mrtrix.org/nicdc/32/1779_2.png) [@NicDC](https://community.mrtrix.org/u/NicDC)
#### Post date: [September 20, 2022, 2:46pm UTC](https://community.mrtrix.org/t/dwi-to-t1w-alignment-but-poor-effect/6051/2 "2022-09-20T14:46:18Z")

</div>

Dear @hyting ,

Your code looks fine (if you intend to move the DWI to the T1 and not the other way around), but this can happen for various reasons and sometimes it might take a bit of trial and error to get a good registration.

Try outputting the registered mean\_b0 from the FLIRT step (using the -o flag) and see if that worked as expected (overlay that file as you have done now) - likely it hasn’t and that’s why you have downstream issues. You can try using a different cost function to see if that does the trick.

Hope this helps,  
Nick

---

<div class="post-metadata">

### Author: ![fionaEyoung](https://community.mrtrix.org/user_avatar/community.mrtrix.org/fionaeyoung/32/3826_2.png) [@fionaEyoung](https://community.mrtrix.org/u/fionaEyoung)
#### Post date: [September 20, 2022, 3:38pm UTC](https://community.mrtrix.org/t/dwi-to-t1w-alignment-but-poor-effect/6051/3 "2022-09-20T15:38:43Z")

</div>

In addition to Nick’s suggestions, in my experience FLIRT can struggle with images that include a lot of non-brain tissue (i.e. full head scan with neck etc.). You might get better results by first running FSL’s `bet` on your T1 image (may also take trial and error; I often find I need to provide it with the brain center of mass voxel using the `-c` option) and running registration on the brain-only image.

---

<div class="post-metadata">

### Author: ![hyting](https://community.mrtrix.org/letter_avatar_proxy/v4/letter/h/ed655f/32.png) [@hyting](https://community.mrtrix.org/u/hyting)
#### Post date: [September 22, 2022, 8:36am UTC](https://community.mrtrix.org/t/dwi-to-t1w-alignment-but-poor-effect/6051/4 "2022-09-22T08:36:55Z")

</div>

Hi, fiona,  
According to your suggestion, I ran the same codes with the T1w after bet, this time the alignment works better.  
Thank you a lot! ^ ^  
Best,  
yuting

---

<div class="post-metadata">

### Author: ![samuelholly](https://community.mrtrix.org/user_avatar/community.mrtrix.org/samuelholly/32/2866_2.png) [@samuelholly](https://community.mrtrix.org/u/samuelholly)
#### Post date: [September 23, 2022, 10:32am UTC](https://community.mrtrix.org/t/dwi-to-t1w-alignment-but-poor-effect/6051/5 "2022-09-23T10:32:22Z")

</div>

Hello,

In addition to the above suggestions, you can also look into the `epi_reg` script from the FSL. It is designed specifically for DWI to T1 registration.

From my experience it is very robust.

You will need both brain extracted and whole head T1 images for this approach.

More info can be found here [FLIRT/UserGuide - FslWiki](https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/FLIRT/UserGuide)

---

<div class="post-metadata">

### Author: ![hyting](https://community.mrtrix.org/letter_avatar_proxy/v4/letter/h/ed655f/32.png) [@hyting](https://community.mrtrix.org/u/hyting)
#### Post date: [September 23, 2022, 12:13pm UTC](https://community.mrtrix.org/t/dwi-to-t1w-alignment-but-poor-effect/6051/6 "2022-09-23T12:13:01Z")

</div>

Hello,  
Following your sugguestion, I registered the dwi to T1w with `epi_reg`, and as you said, it works excellent! Except the alignment image, it also generated the wmedge.nii.gz and wmseg.nii.gz. And I compared the `flirt.fsl` alignment image with `epi_reg` 's, they are exactly the same. But the `epi_reg` works better with wmedge.nii.gz and wmseg.nii.gz than `5tt2gmwmi` and `5ttgen` does.

Thank you for your recommendation! 🥰

Best,  
yuting.
