# T1-like contrast from DWI data

**URL:** <https://community.mrtrix.org/t/t1-like-contrast-from-dwi-data/2782>\
**Category:** Uncategorized\
**Created:** [September 5, 2019, 10:25am UTC](https://community.mrtrix.org/t/t1-like-contrast-from-dwi-data/2782 "2019-09-05T10:25:15Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mlyon](https://community.mrtrix.org/user_avatar/community.mrtrix.org/mlyon/32/2046_2.png) [@mlyon](https://community.mrtrix.org/u/mlyon)\
**Post date:** [September 5, 2019, 10:25am UTC](https://community.mrtrix.org/t/t1-like-contrast-from-dwi-data/2782/1 "2019-09-05T10:25:15Z")

</div>

Hi MRtrixperts,

It is that time again; where I reluctantly crawl out of my cave of ‘lurking around the web in hopes of finding answers to previously asked questions’.

I’m attempting to preprocess DWI data in accordance with [this method](https://www.ncbi.nlm.nih.gov/pubmed/25827811) as we have not acquired a blipup/blipdown pair for topup. In order to non-linearly register the DWI to T1-space, I need to invert one of the images’ contrast so that they match each other.

Here’s where the plot thickens. I saw @rsmith mentioned in a [thread](https://community.mrtrix.org/t/preprocessing-questions/995/2) from 2017 that a [method](https://www.researchgate.net/publication/307862882_Generating_a_T1-like_contrast_using_3-tissue_constrained_spherical_deconvolution_results_from_single-shell_or_multi-shell_diffusion_MR_data), not available at the time, would one day solve this problem. I know progress on ssmt has been made (?) but the last piece of the puzzle eludes me:

> finding weights to reproduce the _distribution_ of intensities in the T1-weighted image

Is this possible to do within the MRtrix3 suite? Am i barking up the wrong tree with this one?

Alternatively, I know that `mrhistmatch` has had `nonlinear` functionality added to it to be able to handle situations like this. Unfortunately though I can’t seem to get it to work. The form of command I am using is shown below:  
`mrhistmatch nonlinear t1_brain.nii.gz b0_avg_brain.nii.gz t1_inv_non-linear.nii.gz -mask_input t1_mask.nii.gz -mask_target b0_avg_brain_mask.nii.gz `

Unfortunately the results aren’t as intended:

> T1-Weighted Image
> 
> ![42%20pm](https://community.mrtrix.org/uploads/default/original/2X/4/405449ebbc68664a8c90977d27dca6e2927544ec.jpeg)  
> B0 DWI Image  
> ![39%20pm](https://community.mrtrix.org/uploads/default/original/2X/d/d5c7db1ed688d14edf9ee2ba17bfef3fb77606d4.jpeg)  
> T1 “DWI” Weighted Image  
> ![03%20pm](https://community.mrtrix.org/uploads/default/original/2X/5/528be05ff85d9a17ca3952b254f663aebbf32637.jpeg)

As you can see, the contrast inversion has not quite worked. I have also tried switching target and input images around, no luck. Any help on this topic would be greatly appreciated.

Many Thanks

Matt

---

<div class="post-metadata">

**Author:** ![Roey\_Schurr](https://community.mrtrix.org/user_avatar/community.mrtrix.org/roey_schurr/32/3922_2.png) [@Roey\_Schurr](https://community.mrtrix.org/u/Roey_Schurr)\
**Post date:** [September 5, 2019, 11:43am UTC](https://community.mrtrix.org/t/t1-like-contrast-from-dwi-data/2782/2 "2019-09-05T11:43:39Z")

</div>

Hi Matt,

Perhaps you could obtain an image with similar contrast to a T1-weighted image, using the sphrical harmonics decomposition of the diffusion signal:

[Anisotropic Power Maps: A diffusion contrast to reveal low anisotropy tissues from HARDI data](https://www.semanticscholar.org/paper/Anisotropic-Power-Maps-%3A-A-diffusion-contrast-to-Dell'Acqua-Lacerda/49ffa9565b5f6df6499b3649f4700746d0c5271f)

It might be good enough for registration purposes. What do you think?  
Best,  
Roey

---

<div class="post-metadata">

**Author:** ![ThijsDhollander](https://community.mrtrix.org/user_avatar/community.mrtrix.org/thijsdhollander/32/1617_2.png) [@ThijsDhollander](https://community.mrtrix.org/u/ThijsDhollander)\
**Post date:** [September 11, 2019, 2:00am UTC](https://community.mrtrix.org/t/t1-like-contrast-from-dwi-data/2782/3 "2019-09-11T02:00:40Z")

</div>

> [@mlyon](#):
>
> I’m attempting to preprocess DWI data in accordance with [this method](https://www.ncbi.nlm.nih.gov/pubmed/25827811) as we have not acquired a blipup/blipdown pair for topup. In order to non-linearly register the DWI to T1-space, I need to invert one of the images’ contrast so that they match each other.

> [@mlyon](#):
>
> Unfortunately the results aren’t as intended:

No, I’m not surprised, I’ve seen exactly that before. There is no good one-to-one mapping in that case. Sometimes it might get a bit closer (as probably did in that paper), but most of the time this is off way to much to be useful. We noticed this in our lab as well, when we desperately needed a solution for this work: [Fibre-specific white matter reductions in Alzheimer’s disease and mild cognitive impairment | Brain | Oxford Academic](https://academic.oup.com/brain/article/141/3/888/4788771) , and even more so the follow up work (where lesions needed to align accurately between T1, FLAIR _and_ dMRI data): [https://www.biorxiv.org/content/10.1101/623124v1.full](https://www.biorxiv.org/content/10.1101/623124v1.full) .

We ended up with a fully working solution that’s based on _this_ mechanism to produce a T1-like contrast (this will greatly add to your web-lurking attempt to find answers 😉 ): [https://www.researchgate.net/publication/307862882\_Generating\_a\_T1-like\_contrast\_using\_3-tissue\_constrained\_spherical\_deconvolution\_results\_from\_single-shell\_or\_multi-shell\_diffusion\_MR\_data](https://www.researchgate.net/publication/307862882_Generating_a_T1-like_contrast_using_3-tissue_constrained_spherical_deconvolution_results_from_single-shell_or_multi-shell_diffusion_MR_data) .

Internally, Rami and myself developed an integrated solution to estimate, and re-estimate, this T1-like contrast during iterations of registration (with outlier rejection, etc…). This worked perfectly well with our data, even with large volumes of white matter lesions (their contrast was estimated correctly too).

However! (buzz-kill follows)

For this to work well with the current registration in MRtrix (which we used at the time), key being that this is currently limited to _squared-difference_ based registration that aims for _exactly matching_ intensities, you’ll need decent bias field correction for the T1w image. This is by the way also _partially_ what causes issues for the other strategy in the results you show; but it’s more complicated there.

Therefore, it’s not robust at all times; I’ve seen it work on some datasets, and perform sub-optimally on others. It’s not always easy to inspect the result, so it’s hard for the average user to identify when it works sub-optimally. So I find it a bit too risky at the moment to just put out there as an integrated solution; people might get inaccurate results and not even realise it.

What I recommend if you want to give something like this a shot in any case is roughly this:

1. Make sure you run some form of bias field correction on the T1w image (ANTs’ N4 algorithm is good for this)
2. Run a form of 3-tissue CSD on your dMRI data. You can go with MSMT-CSD if you’ve got multi-shell data. SS3T-CSD should do the job for single-shell data most of the time. If you need SS3T-CSD, it’s available at [https://3Tissue.github.io](https://3Tissue.github.io) .
3. Once you’ve got a bias field corrected T1w image and 3-tissue maps, make sure they’re at least already reasonably rigidly aligned; so there’s a lot of (correct / accurate) overlap between all relevant tissues (WM - GM - CSF). You can use e.g. FSL’s FLIRT with a normalised mutual information metric for this.
4. Extract the WM map from the WM FOD volume (`mrconvert wmfod.mif wm.mif -coord 3 0`). The GM and CSF from 3-tissue CSD techniques are already “just” maps out of the box.

From here on, follow essentially the steps (as shown in the images) in [https://www.researchgate.net/publication/307862882\_Generating\_a\_T1-like\_contrast\_using\_3-tissue\_constrained\_spherical\_deconvolution\_results\_from\_single-shell\_or\_multi-shell\_diffusion\_MR\_data](https://www.researchgate.net/publication/307862882_Generating_a_T1-like_contrast_using_3-tissue_constrained_spherical_deconvolution_results_from_single-shell_or_multi-shell_diffusion_MR_data) (A-B-C-D-E below match with the image in the abstract):

A. Bias field corrected T1w image; you got this from the steps above.

B. Resample the aligned T1w image to the grid of your diffusion data / 3-tissue CSD result. This might have already been done “automatically” for you if you used e.g. FSL tools to register. Then apply the brain mask you used for your dMRI data. Everything now “lives” on the same grid.

C. 3-tissue CSD result, you got this now as individual tissue maps (GM and CSD directly from 3-tissue CSD, WM from the command above extracted from WM FOD).

D. Normalise to sum to one for each tissue map / compartment. You effectively get tissue [signal fractions](https://www.biorxiv.org/content/10.1101/623124v1.full) then, a useful piece of information for many subsequent analyses. You can e.g. do this per tissue type via mrcalc (assuming `wm.mif` is only a map, see above):

```auto
mrcalc mask.mif wm.mif wm.mif gm.mif csf.mif -add -add -divide 0 -if frac_wm.mif
mrcalc mask.mif gm.mif wm.mif gm.mif csf.mif -add -add -divide 0 -if frac_gm.mif
mrcalc mask.mif csf.mif wm.mif gm.mif csf.mif -add -add -divide 0 -if frac_csf.mif

```

E. Fit the T1w intensities (on the dMRI grid, see above) as a linear combination of these 3 _tissue signal fraction_ maps. The easiest way to do this in any external software (e.g. MATLAB, R, …) is to use `mrdump` with `-mask mask.mif` on each of the `frac_....mif` images above separately (so run it 3 times), and then also on the regridded T1w image. This will give you 3+1 text files, will all intensities in all those images stored in the same matching order. Import this e.g. in MATLAB, and run a least squares estimation with 3 unknowns and as many equations as there are voxels in the mask (i.e. a massive number typically). Do check all input text files first for non-physical or non-finite values such as `NaN` or `Inf` (various steps might introduce these). If they exist, remove the entire equation from the system, i.e. the corresponding entries for each of the 4 text files / vectors at this point.

Finally, once you got the 3 weights, use mrcalc to multiply each with the fraction image and sum, as follows:

```auto
mrcalc frac_wm.mif WM-WEIGHT-HERE -mult frac_gm.mif GM-WEIGHT-HERE -mult frac_csf.mif CSF-WEIGHT-HERE -mult -add simulated_T1w_contrast.mif

```

The final image should resemble your bias field corrected / regridded T1w image closely, similar to figures B and E in the abstract.

As mentioned, even when it closely resembles this successfully, I think I would still not recommend sum or squared differences guided registration: if the intensities are even ever so slightly off, registration can very easily be misguided. At this stage, I’d use the resulting contrast e.g. with FSL FLIRT and in this case normalised cross-correlation as the guiding metric. Set it as such that you’re only after a very, very smooth warp (even when these distortions are large, they’re still relatively smooth in space). Get the warp from FLIRT, get it into MRtrix, apply to the WM FOD image and GM and CSF compartments if you need them.

That explanation got longer than I intended to… 😬 😁

It looks more complicated than it is in practice, but you’ll need some confidence chaining a few tools together, as you notice. I wrote that abstract and generated the results all at once in less than a day; if that can aid confidence (and hopefully not crush it 😊).

Cheers,  
Thijs

---

<div class="post-metadata">

**Author:** ![rsmith](https://community.mrtrix.org/user_avatar/community.mrtrix.org/rsmith/32/2672_2.png) [@rsmith](https://community.mrtrix.org/u/rsmith)\
**Post date:** [October 7, 2019, 9:34am UTC](https://community.mrtrix.org/t/t1-like-contrast-from-dwi-data/2782/4 "2019-10-07T09:34:19Z")

</div>

> I’m attempting to preprocess DWI data in accordance with [this method](https://www.ncbi.nlm.nih.gov/pubmed/25827811) as we have not acquired a blipup/blipdown pair for topup. In order to non-linearly register the DWI to T1-space, I need to invert one of the images’ contrast so that they match each other.

I was only recently having another look at that method myself. Within their implementation in BrainSuite, that contrast matching should be occurring within their processing script, and shouldn’t have to be performed explicitly. Personally I wasn’t able to get results I was happy with, but would be interested to hear from anyone who has managed to get it working well.

I do nevertheless use the same concept myself for doing inter-modal rigid-body registration following DWI pre-processing. What you’re missing out on your attempt is the fact that in order for the gross intensities of the different tissues to be approximately monotonic between the two images, you need to first _invert_ one of the images prior to the non-linear histogram matching; this is just a `mrcalc 1.0 image.mif -div` call. This will also depend on good T1 bias field correction just as for the multi-tissue approach.

---

<div class="post-metadata">

**Author:** ![s66](https://community.mrtrix.org/letter_avatar_proxy/v4/letter/s/f4b2a3/32.png) [@s66](https://community.mrtrix.org/u/s66)\
**Post date:** [June 22, 2021, 8:05am UTC](https://community.mrtrix.org/t/t1-like-contrast-from-dwi-data/2782/5 "2021-06-22T08:05:44Z")

</div>

Hi @ThijsDhollander

Sorry, I am a beginner and just start to use MRtrix for histogram matching of MRI images. The command that I use is as

```auto
mrhistmatch nonlinear /home/sub-102_space-T2S_desc-masked_T2S.nii.gz /home/3_T2_MRI_SWI_BFC_50mm_HM.nii.gz /home//102_T2_MRI_SWI_BFC_50mm_HMFinal.nii.gz 

```

I don’t know why it gave me error when I want to add options such as bins or type ?  
error is : [ERROR] Expected exactly 3 arguments (4 supplied)

I appreciate your comments

Saba

---

<div class="post-metadata">

**Author:** ![s66](https://community.mrtrix.org/letter_avatar_proxy/v4/letter/s/f4b2a3/32.png) [@s66](https://community.mrtrix.org/u/s66)\
**Post date:** [June 29, 2021, 11:32pm UTC](https://community.mrtrix.org/t/t1-like-contrast-from-dwi-data/2782/6 "2021-06-29T23:32:38Z")

</div>

Hi There,

Would you please help me with that command. I am a beginner and use this command to do histogram matching. But it gave me error when I add (nonlinear" option to the command line.  
I appreciate your comments.

```auto

mrhistmatch nonlinear '-bins' 100 '-force' /home/mom008/mmm1/sub-102_space-T2S_desc-masked_T2S.nii.gz /home/mom008/mmm1/3_T2_MRI_SWI_BFC_50mm_HM.nii.gz /home/mom008/mmm1/102_T2_MRI_SWI_BFC_50mm_HM999.nii.gz 

```

---

<div class="post-metadata">

**Author:** ![rsmith](https://community.mrtrix.org/user_avatar/community.mrtrix.org/rsmith/32/2672_2.png) [@rsmith](https://community.mrtrix.org/u/rsmith)\
**Post date:** [August 2, 2021, 9:25am UTC](https://community.mrtrix.org/t/t1-like-contrast-from-dwi-data/2782/7 "2021-08-02T09:25:37Z")

</div>

Hi Saba,

It seems as though you are using an older version of _MRtrix3_; version `3.0_RC2` at the latest. The linear histogram matching modes were not yet implemented, and so the “`nonlinear`” mode specification was not necessary since it was the only mode available. See the difference in help pages between [`3.0_RC2`](https://mrtrix.readthedocs.io/en/3.0_rc2/reference/commands/mrhistmatch.html) and [`3.0_RC3`](https://mrtrix.readthedocs.io/en/3.0_rc3/reference/commands/mrhistmatch.html).

Since these version mismatches do come up from time to time, I threw together a [Wiki page](https://community.mrtrix.org/t/information-on-software-versions/5091) where we can hopefully more efficiently direct people when these issues arise.

Cheers  
Rob
