# Synb0 for dwifslpreproc: How?

**URL:** https://community.mrtrix.org/t/synb0-for-dwifslpreproc-how/6386
**Category:** Uncategorized
**Created:** [February 9, 2023, 3:16pm UTC](https://community.mrtrix.org/t/synb0-for-dwifslpreproc-how/6386 "2023-02-09T15:16:14Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![AmirHussein](https://community.mrtrix.org/user_avatar/community.mrtrix.org/amirhussein/32/5014_2.png) [@AmirHussein](https://community.mrtrix.org/u/AmirHussein)
#### Post date: [February 9, 2023, 3:16pm UTC](https://community.mrtrix.org/t/synb0-for-dwifslpreproc-how/6386/1 "2023-02-09T15:16:15Z")

</div>

Hi all,

I am currently analyzing a dataset (b=1000, 64dir, PE-dir=j-) without any RPE acquisitions and I am using Synb0-DISCO. This topic may cover both Synb0 and MRtrix, and I want to double-check whether I have done things correctly:

The steps for each subject:

1. Denoise and Gibbs ringing removal, and then b0 extraction
2. Provide acqparams.txt as: [0 -1 0 readout; 0 -1 0 0]
3. Run Synb0-DISCO with OUTPUTS and INPUTS in the same main analysis folder
4. dwifslpreproc dwi\_denoised\_unringed.mif dwi\_preprocessed.mif -rpe\_none -pe\_dir j- -readout readout -eddy\_options=" …/Synb0\_outputs/topup"

Any comments?

Best,  
Amir

---

<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: [February 10, 2023, 1:09pm UTC](https://community.mrtrix.org/t/synb0-for-dwifslpreproc-how/6386/2 "2023-02-10T13:09:15Z")

</div>

Hi Amir

I’m not going to weigh in on the “correctness” of your approach, because I don’t know any better. But since I’ve also done some experiments with synb0-disco I thought I’d document my steps here for you so we can compare notes 🙂

What I remember is that I had quite a bit of fiddling around to do to get the directions right, maybe due to the interactions of strides / pe dir? I have vague memories of distortion corrections applied the wrong way (so exaggerating the distortion) and struggling to reproduce results between `dwifslpreproc`, the `topup` outputs created by synb0-disco, and manually using `topup`.

Anyhow, this is the process I seem to have ended up with.

1. ☑ `dwidenoise` → `mrdegibbs` → `INPUTS/b0.nii.gz` (I don’t have a record of the exact way I extracted `b0.nii.gz`
2. ☑ same here

```auto
cat synb0-disco/INPUTS/acqparams.txt
0 -1 0 0.05225
0 -1 0 0

```

3. ☑ (I had to run synb0-disco in singularity on an HCP cluster because of [RAM limitations](https://github.com/MASILab/Synb0-DISCO/issues/29#issuecomment-1202484969))
4. This part I did differently, again not entirely sure why, but I opted to do both `topup` and `eddy` using the `dwifslpreproc` wrapper, so my commands look like this:

```bash
$ mrconvert synb0-disco/OUTPUTS/b0_all.nii.gz synb0_out.mif -import_pe_table synb0-disco/INPUTS/acqparams.txt -strides '-1,+2,+3,+4'
# where eddy_indices is as many 1s as volumes in degibbs.mif, 31 in my case
$ cat eddy_indices.txt
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
$ mrconvert degibbs.mif eddy_in.mif -import_pe_eddy synb0-disco/INPUTS/acqparams.txt eddy_indices.txt -strides '-1,+2,+3,+4'
$ dwifslpreproc eddy_in.mif topup_eddy_done.mif -rpe_header -se_epi synb0_out.mif

```

Not particularly helpful in validating your approach I’m afraid, but I usually find it useful seeing what others have done. Good luck, and I’d be interested to hear about what you think of the results!

Fiona

---

<div class="post-metadata">

### Author: ![AmirHussein](https://community.mrtrix.org/user_avatar/community.mrtrix.org/amirhussein/32/5014_2.png) [@AmirHussein](https://community.mrtrix.org/u/AmirHussein)
#### Post date: [February 20, 2023, 12:25pm UTC](https://community.mrtrix.org/t/synb0-for-dwifslpreproc-how/6386/3 "2023-02-20T12:25:51Z")

</div>

Hi Fiona,

Thanks for your reply, and yes, I am having the same struggle as yours most possibly due to the interactions of strides between T1 and b0s. The pipeline I used generated topup\_fieldcoeff.nii.gz with anterior-posterior being reversed (see below; look for the eyeballs in posterior!). I am not sure whether Left-Right was also distorted or not. This resulted in an extreme distortion in the preprocessing step.

 ![image](https://community.mrtrix.org/uploads/default/original/2X/a/a0bb05747d41dbcd04007bfacb1927bd2ca8c7ce.png)

So, what I did was to run `fslreorient2std` on both b0 and T1 in the INPUT folder, rerun Synb0 without any flags, and then pass the topup outputs to the dwifslpreproc.

The results are so far so good!

Amir

---

<div class="post-metadata">

### Author: ![Bastiaan\_van\_Tol](https://community.mrtrix.org/user_avatar/community.mrtrix.org/bastiaan_van_tol/32/4617_2.png) [@Bastiaan\_van\_Tol](https://community.mrtrix.org/u/Bastiaan_van_Tol)
#### Post date: [April 26, 2024, 9:40am UTC](https://community.mrtrix.org/t/synb0-for-dwifslpreproc-how/6386/4 "2024-04-26T09:40:32Z")

</div>

Hi Fiona,

I am trying to replicate your pipeline for my current analyses, however for the command -import\_pe\_eddy, I don’t understand which information eddy\_indices.txt holds and from which function this is the output. Is this related to the Synb0-DISCO pipeline, or pre-processing steps using MRtrix?

Best,  
Bastiaan

---

<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: [April 26, 2024, 12:31pm UTC](https://community.mrtrix.org/t/synb0-for-dwifslpreproc-how/6386/5 "2024-04-26T12:31:04Z")

</div>

Hi Bastian

It’s been some time since I did this (and I don’t have the files to hand unfortunately) but I believe the key is in the comment line in that code snippet

> [@fionaEyoung](#):
>
> `# where eddy_indices is as many 1s as volumes in degibbs.mif, 31 in my case`

This isn’t the output from any function, it’s simply a text file I wrote manually, and is just a list of n 1s where n is the size of the 4th dimension in your input DWI file.

> **Here is some background that might make things clearer**
>
> I’ll take a step back. (And note, this is just the pipeline I came up with; there’s not necessarily an established “correct” way to use Synb0-disco and MRtrix together.)
> 
> Synb0 takes your (EPI distorted) b\_0 image, plus you aligned T1 image, and attempts to generate a perfect, hypothetical, undistorted b\_0 image corresponding to the impossible acqparams `0 -1 0 0` (i.e. readout=0, infinite pixel bandwidth).
> 
> Topup takes two input EPI images with different acqparams (usually _different PE directions_ but same readout time) to estimate the susceptibility field, which is in turn used to un-distort all the other DWI volumes. The trick of Synb0 is that, since we don’t have an RPE pair, we instead use this fake infinte bandwidth image as the second topup input, the difference between the two being in the _readout time_ (instead of the PE directions).
> 
> Having generated the fake second undistorted EPI image (`synb0-disco/OUTPUTS/b0_all.nii.gz`), the synb0 program will additionally run topup for you using `b0_all.nii.gz` as input, and then apply the estimated susceptibility field to the entire input series using `applytopup`. _This is the bit that I found didn’t work with my images, because of funky stride and PE-dir interactions, and where my pipeline differs from Amir’s_. The topup and applytopup results produced by synb0 did not properly undistort my images, as discussed above.  
> So instead, I directly took the generated undistorted b\_0 image (paired with the original input distorted b\_0, hence the filename `b0_all`) and ran topup and eddy manually using `dwifslpreproc`.

`dwifslpreproc` can use input options like `-rpe_pair` and `-pe_dir ap` to figure out the PE direction and readout info to feed to topup, which for the usual application is fine.  
But because we have a funky input with same PE and different readout times we have to encode this information in the header (analogous to the embedded DW gradient tables feature of `.mif` images) and tell `dwifslpreproc` we’ve done this with the `-rpe_header` flag (the only viable option out of the [compulsory `-rpe_*` options](https://mrtrix.readthedocs.io/en/latest/reference/commands/dwifslpreproc.html#options-for-specifying-the-acquisition-phase-encoding-design-note-that-one-of-the-rpe-options-must-be-provided)). This was already done for the paired b0 in the first step (`mrconvert ...`). We also need to include the PE information in the input DWI series (i.e. the whole acquisition we want to de-distort).

There are two ways of embedding the PE table using `mrconvert`, see here: [mrconvert - Options for exporting phase-encode tables](https://mrtrix.readthedocs.io/en/latest/reference/commands/mrconvert.html#options-for-exporting-phase-encode-tables). I opted for the

- -import\_pe\_eddy config indices import phase-encoding information from an EDDY-style config / index file pair

version. See the Eddy documentation ([2.3.3 “running eddy”](https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/eddy/UsersGuide#Running_eddy-1)) for information on the index file. I created the file `eddy_indices.txt` to indicate that every image (n=31 in my case) in the input series (`eddy_in.mif`) was acquired with PE parameters corresponding to line 1 of `acqparams.txt`.  
You could alternatively construct a PE table file `pe_table.txt` which would consist of the first line of `acqparams.txt` repeated n times and embed it using `-import_pe_table pe_table.txt` instead.

## TLDR

> [@Bastiaan\_van\_Tol](#):
>
> I don’t understand which information eddy\_indices.txt holds and from which function this is the output.

`eddy_indices.txt` is a manually constructed file containing a list of indices (starting from 1, not 0) indicating, for every volume in the input DWI series (`degibbs.mif` in the code snipped above), which line in the corresponding `acqparams.txt` file describes the phase encoding parameters for that volume. In this case, they’re all the same, because the original acquisition only used one phase encoding direction / readout time configuration, namely `0 -1 0 0.05225`.

This file is used to embed phase encoding information in the `.mif` headers, information used by `dwifslpreproc` to correctly apply topup using the synb0 generated undistorted b0 file.

Hope that helps!  
Fiona

---

<div class="post-metadata">

### Author: ![Bastiaan\_van\_Tol](https://community.mrtrix.org/user_avatar/community.mrtrix.org/bastiaan_van_tol/32/4617_2.png) [@Bastiaan\_van\_Tol](https://community.mrtrix.org/u/Bastiaan_van_Tol)
#### Post date: [April 29, 2024, 4:50pm UTC](https://community.mrtrix.org/t/synb0-for-dwifslpreproc-how/6386/6 "2024-04-29T16:50:04Z")

</div>

Thank you Fiona for your elaborate answer! It provides me with a deeper understanding of how the functions work. I managed to get everything set up and working appropriately. The EPI distortion correction looks great.

Best,  
Bastiaan

---

<div class="post-metadata">

### Author: ![Candy](https://community.mrtrix.org/letter_avatar_proxy/v4/letter/c/67e7ee/32.png) [@Candy](https://community.mrtrix.org/u/Candy)
#### Post date: [March 17, 2025, 12:18pm UTC](https://community.mrtrix.org/t/synb0-for-dwifslpreproc-how/6386/7 "2025-03-17T12:18:12Z")

</div>

Hi Fiona,

I am trying to replicate your pipeline, and before synb0-disco:v3.1, the dwi data is preprocessed only by dwidenoise. When I running the code as the same as yours, I ran into an error after synb0-disco. I don’t know which step is wrong. I guess maybe we have different Mrtrix3 version, mine is 3.0.3. Additionally, my eddy\_indices.txt is 35 1s and my data has 75 slices, maybe the odd/even slices of data can influence the process?

error is here:  
dwi2mask dwi\_pad2\_pe\_0\_applytopup.mif - | maskfilter - dilate - | mrconvert - eddy\_mask.nii -datatype float32 -strides -1,+2,+3

dwi2mask: preloading data for “dwi\_pad2\_pe\_0\_applytopup.mif”… [==================================================]  
dwi2mask: [ERROR] no valid diffusion gradient table found  
dwi2mask: [ERROR] error importing diffusion gradient table for image “dwi\_pad2\_pe\_0\_applytopup.mif”  
maskfilter: [ERROR] no filename supplied to standard input (broken pipe?)  
maskfilter: [ERROR] error opening image “-”  
mrconvert: [ERROR] no filename supplied to standard input (broken pipe?)  
mrconvert: [ERROR] error opening image “-”

If you ever ran into the same problem? I am sincerely looking forward to your reply.

Best,  
Candy
