Number of volumes in gradient table does not match input image

Dear MRtrix3 community:

I am trying to learn MRtrix3 for my research, so I started to play with commands, but I am having problem with this script:

dwipreproc -rpe_none 2 ./Downloads/anger/anger_mrconverted.mif ./Downloads/anger/anger_out.mif

and I got this error:

dwipreproc: [ERROR] Number of volumes in gradient table does not match input image

Can you tell me what is the problem?

Have a nice day,

Aldo

You’d get this message if your input data contains a DW gradient table, but the number of entries in it doesn’t match the number of volumes in your DWI file (here’s where it comes from). This would be confirmed using mrinfo, e.g.:

mrinfo ./Downloads/anger/anger_mrconverted.mif 

if that reports a different number of volumes than entries in your DW scheme, that’s the problem. For a well-formed input, this should look like:

  Dimensions:        104 x 104 x 54 x 167
...
  dw_scheme:         [ 167 entries ]

Assuming that’s the problem, it’s difficult to help without knowing the particular of how your input DWI data were produced…

Hi jdtournier:

I got this from the script:

mrinfo ./Downloads/anger/anger_mrconverted.mif


Image: “./Downloads/anger/anger_mrconverted.mif”


Dimensions: 128 x 128 x 75 x 3
Voxel size: 2 x 2 x 2 x ?
Data strides: [ -1 -2 3 4 ]
Format: MRtrix
Data type: 32 bit float (little endian)
Intensity scaling: offset = 0, multiplier = 1
Transform: 0.9216 0.3427 0.1823 -167.2
-0.3317 0.9392 -0.0889 -46.17
-0.2016 0.02147 0.9792 -39.28
comments: ANGER SONIA (3722852Q) [MR] DTI_64dir_Strict_Stricte_ISO
study: IRM �tude fonctionnelle de l’enc�phale
DOB: 26/09/1969
DOS: 06/06/2016 15:15:14
dw_scheme: [ 65 entries ]
mrtrix_version: 0.3.15-487-gfe406080-dirty

Well, here’s your answer:

Dimensions: 128 x 128 x 75 x 3
...
dw_scheme: [ 65 entries ]

You have 3 volumes in your image, yet your DW scheme consists of 65 entries. You need to have a look at where your data come from, and make sure you actually have a proper diffusion MRI acquisition here.

Hi jdtournier:

I am providing the gradient file which is in the file grad_matrix.txt with the following script:

mrconvert /home/brain/Downloads/anger/anger_mrconverted.mif /tmp/dwipreproc-tmp-PV1O3B/series.mif -grad /home/brain/Downloads/anger/grad_mrtrix

The grad_matrix.txt is like this:

0 0 0 0
-0.99997932 -0.00502885 0.00402893 1000
-0.00299386 -0.9999831300000001 -0.00499472 1000
-0.02928309 -0.6526547700000001 0.75708914 1000
0.5896793 0.76892352 0.24705279 1000
-0.23540172 0.52876884 0.81546891 1000
0.8957705500000001 -0.25558853 -0.36368933 1000
-0.79849392 0.12466961 -0.58895248 1000
0.23017962 -0.93230259 0.2789799 1000
-0.93747205 0.13605693 -0.32036671 1000
0.50595194 0.84573311 -0.16955316 1000
0.3473542 0.84956193 -0.39697543 1000
0.4584136 0.63474995 -0.62205249 1000
-0.48681957 0.39399886 0.77959716 1000
0.61810315 0.67582327 -0.40151152 1000
-0.57891911 0.1007914 -0.80913156 1000
-0.82529134 0.52502126 0.20795973 1000
-0.89599895 -0.04370159 0.44190052 1000
0.29182678 0.5455873 -0.78560281 1000
0.11850379 0.96344841 -0.24025802 1000
-0.79995286 -0.40796188 -0.44004852 1000
-0.51075685 0.84289253 -0.16929121 1000
-0.79002476 -0.15783753 -0.59240878 1000
0.94897711 0.23822185 0.20662214 1000
0.23030554 -0.78628951 0.5733307 1000
-0.02049026 0.19200473 -0.98118019 1000
0.21739192 0.95673805 0.1933728 1000
-0.77234411 -0.60763174 -0.18511713 1000
0.16193648 0.3598817 -0.91883737 1000
0.14829214 0.73502749 0.66162217 1000
0.88703299 -0.42126235 0.18897216 1000
0.56302071 0.23625594 0.79195392 1000
0.3829605 0.14666282 -0.91204774 1000
-0.30383378 0.20252153 -0.93095112 1000
-0.33208829 0.13400923 0.9336803 1000
-0.96432257 0.26034477 0.0479862 1000
-0.95967799 -0.20891927 0.1880714 1000
0.45179814 0.88985622 0.06351949 1000
-0.77263105 -0.6294553899999999 0.08262637 1000
-0.70828283 0.41256905 -0.57281977 1000
0.6956839 0.02784398 -0.71780819 1000
-0.68081319 0.53359932 0.50176221 1000
-0.14027384 0.72905898 0.66992283 1000
-0.74175829 -0.39170146 0.54439408 1000
-0.1060506 -0.82448345 0.55585998 1000
0.5839130300000001 0.60016322 0.5466714499999999 1000
-0.08674411 0.33940467 0.93663234 1000
-0.55012167 0.79572499 0.25335315 1000
-0.8384366599999999 -0.46101961 0.29066321 1000
0.36500943 0.5645451500000001 0.74030852 1000
0.18632901 0.39666799 0.89885277 1000
-0.71761936 0.69630486 0.0134971 1000
0.43234488 -0.68643069 -0.58471435 1000
-0.49976689 0.69425905 -0.5179165 1000
-0.16828923 0.51322842 -0.84159094 1000
-0.46131617 0.42733845 -0.77754039 1000
0.38556409 0.81165797 0.43880749 1000
-0.71376604 0.25183541 0.65354198 1000
-0.25843555 0.88740671 0.38173336 1000
0.00092807 0.08040165000000001 0.9967621 1000
0.03811662 0.90453398 0.42469409 1000
0.57260901 0.30712062 -0.76012915 1000
0.28221089 0.14964631 0.94760919 1000
-0.7191928 0.61237556 -0.32826522 1000
-0.26348454 0.9604848 0.08969354 1000

Sorry, I made a copy paste mistake, the script that I am using is:

dwipreproc -rpe_none 2 ./Downloads/anger/anger_mrconverted.mif ./Downloads/anger/anger_out_dwipreproc.mif -grad ./Downloads/anger/grad_mrtrix

Aldo

So there doesn’t seem to be anything wrong with your DW encoding. As I’d mentioned earlier, the issue seems to be that you only have 3 volumes in your input DW image - there’s no way that can be the full DWI image series, you’ll need to investigate where the data came from to figure out what went wrong.

So you mean that

The right dimensions should be
Dimensions: 128 x 128 x 75 x 65 ?

Thanks a lot in advance,

Aldo

So, what is the right order of commands to use dwipreproc if you have a sequence of DICOM images?

Thanks a lot,

Aldo

If your DW encoding file is correct, yes. There’s just no meaningful diffusion analysis you can do with just 3 volumes… And judging by the fact that you’re trying to provide a 65 DW direction encoding, I’m guessing you’re expecting your data to match that - they don’t.

More or less what you had, but just provide the enclosing DICOM folder for the input data. And if your DICOM data are half-decent, you shouldn’t need to provide the DW encoding separately, it should already be in the DICOM headers. So this might look something like (depending on where your DICOM data reside):

dwipreproc -rpe_none 2 ./Downloads/anger/DICOM ./Downloads/anger/anger_out.mif

If you still get an error about the DW encoding not matching, then my guess is either the data you’re trying to process are not the raw diffusion data, or they were produced by some non-standard implementation (data from the 3 major MRI manufacturers should be fine). Bear in mind that the data may look like a diffusion sequence, but might correspond to a derived metric; for instance, on Siemens scanners, you’ll often find the raw DW series, followed by other similarly named series that correspond to the FA, MD, DEC, etc. (my guess is you have the DEC, given that it comes out as 3 volumes). You need to pick out the raw DW series.

Hi! I am encountering the same problem, but when I try to check my dsi.mif file with mrinfo, I don’t retrieve the field dw_scheme, just:

Dimensions: 154 x 154 x 78 x 129
Voxel size: 1.68831 x 1.68831 x 1.6 x ?
Data strides: [ -1 -2 3 4 ]
Format: NIfTI-1.1
Data type: unsigned 16 bit integer (little endian)
Intensity scaling: offset = 0, multiplier = 1
Transform: 0.9981 0.04533 -0.04066 -136
-0.05072 0.9884 -0.1434 -92.5
0.03368 0.1452 0.9888 -9.011
comments: RECHERCHE_A_JOUR_P
mrtrix_version: 3.0_RC2-117-gf098f097

Seems to be the case for all mif files… Does that depend on the mrtrix version?

Thanks in advance!

Hi Maria,

The image for which you have provided the output of running mrinfo is in fact a NIfTI image, not a .mif (see “Format:” field). This format is fundamentally incapable of encoding the diffusion gradient table within the image header; that feature only applies to the MRtrix image format. See documentation on image formats here, and on gradient scheme handling here.

MRtrix3 will capture the gradient table at DICOM import, and propagate it from input to output image for all MRtrix3 commands where appropriate. However if you convert to NIfTI (or any other format) at any point during your processing chain, this information will be lost from the header, and will therefore also be absent from all subsequently-generated images - unless you explicitly import it using one of the -grad or -fslgrad options.

Rob

Hi Rob,

thanks a lot for your quick and clear answer! And sorry for a really basic question, just started using mrtrix.
I was indeed doing a DICOM to NIfTI conversion without the - export_grad_mrtrix / -export_grad_fsl option to export the gradient table, so impossible to retrieve that info later.

Cheers,
Giulia