Gradient encoding matrix does not represent a HARDI sequence

Hello
I am trying to process some exvivo high resolution DWI. The data were processed using TORTOISE has 7 b=0 and 121 b = 4800. After preprocessing the data were exported in the FSL format - a 4D nifti file with a bvals and bvecs file.
I have processed these same data using MRtrix2 without any major issues. I tried to create a brain mask using the instructions provided on the documentation website. But got this error:
Gradient encoding matrix does not represent a HARDI sequence
It looks like MRtrix3 doesn’t use the bvals and bvecs files available in the same folder.
Can you tell me how to reformat the preprocessed data into a format that MRtrix3 understand?

Thank you

Cibu

I assume you used the -fslgrad option to pass the bvecs/bvals to the command? Otherwise the error message would refer to the gradient table dimensions being invalid. It seems MRtrix3 is having trouble splitting up your encoding into shells. What does this report (substitute the correct filenames):

mrinfo dwi.nii -grad bvecs bvals -dwgrad

Maybe you can post the output of that command, and your bvecs/bvals file here so we can take a look?

Hi Jacque
Here’s the output from mrinfo. I did not use the -fslgrad option. Can you tell me how to use this option?
thank you!

mrinfo GB8A_12feb16_DMC_L0_RAW_4D.nii -grad bvecs bvals -dwgrad
      0       0       0       0       0       0 0.24486 0.11594 0.55356 0.39736 -0.8411 -0.6856 -0.7411 -0.7523 -0.1082 -0.2456 -0.4246 -0.3971 0.52497 0.46612 -0.2047 -0.0002 0.86615 0.85096 -0.5267  -0.467 0.18693 -0.0001 -0.9847 -0.9949 0.39691 0.18652 0.87102 0.85099 -0.1317 -0.2461  -0.332 -0.1163 0.58359  0.6522 -0.5542 -0.3976 -0.0012 -0.1234 0.75041 0.61441 0.78859 0.65058 -0.0002 0.21166 -0.7901 -0.6533 0.61423 0.75074 0.25419 0.34691 -0.4741 -0.3691 0.89882 0.76448 -0.2558 -0.3488 0.33033 0.09466 -0.8711 -0.7414       0 -0.1757 0.93784  0.9454 0.25207 0.09945 -0.5852 -0.6523 0.58393 0.46258 -0.5554 -0.5963 -0.4234 -0.5963 -0.0013 0.24467 0.68435 0.84049 0.74025 0.59578 -0.0006  -0.156 -0.9459 -0.8712 -0.1699 -0.1884 -0.2546 -0.4656  0.1294 0.36696 0.99243 0.97702 -0.5856 -0.8998 0.16957 0.42418 -0.0019  -0.001 -0.8997 -0.7661 0.47211 0.33071 0.47192 0.36651 -0.6862 -0.8417 -0.7522 0.74035 0.84026 0.68359 -0.3699 -0.4745 0.93773 -0.9462 0.55321 0.59529 0.42335 -0.0012  0.9518 0.89841  0.1294  0.7639 -0.3322 -0.0967 -0.7663 0.16973
      0       0       0       0       0       0 0.59513 0.74996 -0.6849 -0.8406 -0.3677  -0.473 0.58438 0.65192 -0.4244 -0.5959 -0.8989 -0.8409 -0.0001  -0.155 0.94548 0.93753 0.46286 0.52521 -0.0003  -0.155  -0.866 -0.8508 -0.0003 -0.1007 0.84067 0.86616 -0.4658 -0.5251 0.42323 0.59549 -0.7407 -0.7501 -0.3314 -0.0951 0.68489 0.84061 -0.2118 -0.0005 0.65064 0.78898       0 0.11605 -0.9949 0.97734 -8.2305 -0.0952 -0.7891 -0.6502  0.1694 -0.0002 -0.5541  -0.397 0.10741 0.24545 0.16926       0 -0.7407 -0.7516 -0.4661  -0.584 0.99245 0.98443  -0.347 -0.2526 -0.2047       0 0.33131 0.11586 0.33125 0.18755 -0.6842 -0.7645 0.89653 0.76472 -0.6142 -0.5953 0.47324 0.36771 -0.5844 -0.7644 0.85072 0.87105 0.25305 0.46618 -0.9519 -0.8656 -0.2046 0.18766 0.42347 0.39693 -0.1227 -0.0004 -0.3306 -0.1074 0.95191 0.89914 0.17547 0.61441 0.10741 0.24592 0.55438 0.74078 -0.5537 -0.3966 0.47309 0.36835  -0.652 0.58449 -0.3674  -0.473 0.39735 0.55449 0.34733 -0.2526 0.68543 0.76485 -0.8963 -0.9373 0.25464 -0.1073 -0.4232 -0.2449 0.74133 0.75215 -0.2449 -0.9517
      0       0       0       0       0       0  0.7654 0.65124 0.47368 0.36798 0.39657  0.5532 0.33052 0.09467 0.89895 0.76454 0.10727 0.36747 0.85111 0.87103 0.25319 0.34788  0.1885 0.00083 0.85001 0.87052 0.46369 0.52541 0.17425  -0.001 0.36839 0.46365 0.15574 0.00107 0.89639 0.76472 0.58396 0.65096 0.74132 0.75204 0.47299 0.36775  0.9773 0.99235 0.11635 0.00052 0.61491 0.75051 0.10084       0 0.61288 0.75106 0.00095 0.11659  0.9522 0.93789 0.68421 0.84026 0.42494 0.59608 0.95178 0.93717 0.58491 0.65272 0.15405 0.33033 0.12258 -0.0005 0.00121  0.2059  0.9458 0.99504 0.74009 0.74899 0.74114 0.86651 0.47255 0.24454 0.13003 0.24407 0.78912 0.76531  0.5547 0.39793 0.33239 0.24634 0.52561 0.46573 0.20274 0.15367 0.25468 0.46374 0.94513 0.86482 0.89662 0.84129 0.00157 0.21312 0.74007 0.42277 0.25516  0.1077 0.98448 0.78898 0.42298 0.59369 0.68539 0.58469 0.68601 0.84161  0.5525 0.39474 0.09444 0.33202 0.39867 0.55585 0.83979  0.6836 0.00177 0.20209 0.47343 0.24622 0.13191 0.34831 0.17095 0.42583 0.89674 0.59704 0.58309 0.65184 0.59389 0.25552
mrinfo: [ERROR] unknown format for image "bvals"
mrinfo: [ERROR] error opening image "bvals"

Just noticed that mrinfo could not open the bvals file. Not sure why since it is in the same format as the bvecs file.
But here are the contents of bvals

0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 4799.86 4800.44 4799.93 4799.98 4799.78 4800.00 4799.84 4778.88 4772.60 4800.32 4772.58 4800.12 4799.75 4744.58 4800.03 4799.91 4799.95 4800.20 4799.76 4744.86 4799.72 4800.20 4729.98 4776.41 4799.54 4799.78 4744.60 4799.76 4800.12 4800.04 4800.45 4800.09 4800.04 4779.01 4800.38 4800.20 4800.48 4800.14 4799.88 4800.14 4799.89 4800.12 4776.50 4800.06 4799.94 4779.14 4799.91 4799.50 4734.23 4799.58 4800.27 4799.97 4772.86 4799.76 4734.02 4800.25 4800.10 4778.66 4744.35 4799.74 4800.13 4729.41 4800.23 4799.89 4800.22 4776.18 4799.89 4800.36 4800.54 4799.94 4800.19 4799.99 4799.73 4799.98 4799.91 4799.69 4799.81 4800.16 4799.63 4800.06 4800.20 4744.35 4799.65 4745.02 4734.21 4799.70 4800.38 4799.89 4800.15 4799.74 4800.39 4800.03 4800.04 4773.19 4733.82 4773.13 4730.02 4800.15 4772.94 4800.26 4800.07 4799.92 4800.03 4800.02 4799.74 4800.40 4779.10 4799.96 4799.98 4800.05 4799.55 4800.13 4800.14 4800.40 4799.71 4800.00 4799.88 4800.46 4733.76 4773.40 4800.02 4799.78 4800.11 4779.24 4799.94 4733.95

OK, you’re using the -grad option, which is suitable for a gradient scheme in MRtrix format (N×4 table, each row is [ X Y Z b ]). For the FSL-style bvecs/bvals pair, you need use -fslgrad:

mrinfo GB8A_12feb16_DMC_L0_RAW_4D.nii -fslgrad bvecs bvals -dwgrad

The reason you get the error at the end is that -grad expects a single argument (the one file for the MRtrix-style encoding), so the command thinks bvals is another regular argument - i.e. another image. The -fslgrad option expects 2 arguments, so would interpret this correctly.

Cheers,
Donald

@jdtournier, I think this is possibly due to your previous post… looks like an error slipped into that one. :wink:

@cibtom, you just need to use the -fslgrad option indeed, so just replace -grad by that to make it work correctly.

Ah crap, yes, quite right. Sorry… :sweat_smile:

Hello,
I meet the same problem:
dwi2mask: [100%] preloading data for "Bi_Sheng_20161116_HEAD_008_DTI.nii"
dwi2mask: [ERROR] Gradient encoding matrix does not represent a HARDI sequence

and the mrinfo as shown below:
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
0.202706 0.518842 -0.83049 1000
0.202706 0.518842 -0.83049 1000
0.202706 0.518842 -0.83049 1000
-0.198047 0.519762 -0.831038 1000
… …
Is there anything wrong with my dwi data? I don’t know how to figure it out now, I am very complicated.

Thank you very much!
Chaoqing

Hi,

Could you provide the full command that you typed, and all its output? There might be clues​ in there.

Also, are you showing the full output of mrinfo, or just the first few lines? If that’s the full output, then the error message is quite appropriate, that’s not enough DW directions to constitute a high angular resolution diffusion imaging scan, there’s only 4 b>0 volumes, that’s not even enough for DTI…

Hi,
This is the command that I typed:

$ mrinfo DTI.nii -fslgrad DTI_bvecs.bvecs DTI_bvals.bvals -dwgrad

Here is the full output:

          0           0           0           0
          0           0           0           0
          0           0           0           0
          0           0           0           0
          0           0           0           0
          0           0           0           0
          0           0           0           0
          0           0           0           0
          0           0           0           0
          0           0           0           0
          0           0           0           0
          0           0           0           0
   0.202706    0.518842    -0.83049        1000
   0.202706    0.518842    -0.83049        1000
   0.202706    0.518842    -0.83049        1000
  -0.198047    0.519762   -0.831038        1000
  -0.198047    0.519762   -0.831038        1000
  -0.198047    0.519762   -0.831038        1000
  -0.402106    0.175219   -0.898671        1000
  -0.402106    0.175219   -0.898671        1000
  -0.402106    0.175219   -0.898671        1000
   0.403303    0.730669    -0.55088        1000
   0.403303    0.730669    -0.55088        1000
   0.403303    0.730669    -0.55088        1000
   0.201694    0.941537   -0.269865        1000
   0.201694    0.941537   -0.269865        1000
   0.201694    0.941537   -0.269865        1000
   0.853331    0.517917  -0.0599043        1000
   0.853331    0.517917  -0.0599043        1000
   0.853331    0.517917  -0.0599043        1000
    0.73127    0.518949   -0.442646        1000
    0.73127    0.518949   -0.442646        1000
    0.73127    0.518949   -0.442646        1000
   0.406741    0.175895    -0.89645        1000
   0.406741    0.175895    -0.89645        1000
   0.406741    0.175895    -0.89645        1000
   0.732279    0.175756   -0.657934        1000
   0.732279    0.175756   -0.657934        1000
   0.732279    0.175756   -0.657934        1000
    0.65025    0.730692    0.207999     999.999
    0.65025    0.730692    0.207999     999.999
    0.65025    0.730692    0.207999     999.999
   0.322199      0.9401    0.111354        1000
   0.322199      0.9401    0.111354        1000
   0.322199      0.9401    0.111354        1000
   0.324202    0.520058    0.790211        1000
   0.324202    0.520058    0.790211        1000
   0.324202    0.520058    0.790211        1000
   0.649822     0.52027    0.554122        1000
   0.649822     0.52027    0.554122        1000
   0.649822     0.52027    0.554122        1000
   0.978649    0.176815    0.104795        1000
   0.978649    0.176815    0.104795        1000
   0.978649    0.176815    0.104795        1000
   0.854419    0.176854    0.488559        1000
   0.854419    0.176854    0.488559        1000
   0.854419    0.176854    0.488559        1000
 -0.0020523    0.731525    0.681811        1000
 -0.0020523    0.731525    0.681811        1000
 -0.0020523    0.731525    0.681811        1000
-0.00342819    0.941802     0.33615        1000
-0.00342819    0.941802     0.33615        1000
-0.00342819    0.941802     0.33615        1000
  -0.654614    0.519491     0.54919     999.999
  -0.654614    0.519491     0.54919     999.999
  -0.654614    0.519491     0.54919     999.999
   -0.33006    0.520515     0.78748        1000
   -0.33006    0.520515     0.78748        1000
   -0.33006    0.520515     0.78748        1000
  -0.197659   -0.175744   -0.964388        1000
  -0.197659   -0.175744   -0.964388        1000
  -0.197659   -0.175744   -0.964388        1000
  -0.203798    0.176373    0.962995        1000
  -0.203798    0.176373    0.962995        1000
  -0.203798    0.176373    0.962995        1000
  -0.651488    0.730295    0.205507        1000
  -0.651488    0.730295    0.205507        1000
  -0.651488    0.730295    0.205507        1000
  -0.324406    0.939937    0.106204        1000
  -0.324406    0.939937    0.106204        1000
  -0.324406    0.939937    0.106204        1000
  -0.199896    0.940286   -0.275508        1000
  -0.199896    0.940286   -0.275508        1000
  -0.199896    0.940286   -0.275508        1000
   -0.40336    0.730891   -0.550544        1000
   -0.40336    0.730891   -0.550544        1000
   -0.40336    0.730891   -0.550544        1000
  -0.731904    0.175418   -0.658441        1000
  -0.731904    0.175418   -0.658441        1000
  -0.731904    0.175418   -0.658441        1000
  -0.728623    0.518245   -0.447806        1000
  -0.728623    0.518245   -0.447806        1000
  -0.728623    0.518245   -0.447806        1000
  -0.852611    0.518506  -0.0648599        1000
  -0.852611    0.518506  -0.0648599        1000
  -0.852611    0.518506  -0.0648599        1000
  -0.857845    0.176676    0.482584     999.999
  -0.857845    0.176676    0.482584     999.999
  -0.857845    0.176676    0.482584     999.999
  -0.979351    0.176103   0.0992904        1000
  -0.979351    0.176103   0.0992904        1000
  -0.979351    0.176103   0.0992904        1000

Before then, I typed the command:

$ dwi2mask DTI.nii DTI_mask

and the output:

dwi2mask: [100%] preloading data for "DTI.nii"
dwi2mask: [ERROR] Gradient encoding matrix does not represent a HARDI sequence

Thank you!
Chaoqing

OK, no issue with your directions then, it’s just a matter of supplying them to any command that needs to know, including dwi2mask. Since the gradient table isn’t stored in the NIfTI header, it needs to be supplied explicitly every time - which is why we recommend MRtrix3’s own mif format.

In your case, you should only need to type:

$ dwi2mask DTI.nii -fslgrad DTI_bvecs.bvecs DTI_bvals.bvals DTI_mask.nii

to get this working… (don’t forget the filename suffix for the output, otherwise MRtrix3 won’t know what format you want for your output).

1 Like

Incidentally, I have to admit that this error message is pretty cryptic - I’ll get that changed now.

Oh~ It works.
The result as shown:
$ dwi2mask DTI.nii -fslgrad DTI_bvecs.bvecs DTI_bvals.bvals DTI_mask.nii
dwi2mask: [100%] preloading data for "DTI.nii"
dwi2mask: [100%] finding min/max of "mean b=0 image"
dwi2mask: [done] optimising threshold
dwi2mask: [100%] thresholding
dwi2mask: [100%] finding min/max of "mean b=1000 image"
dwi2mask: [done] optimising threshold
dwi2mask: [100%] thresholding
dwi2mask: [done] computing dwi brain mask
dwi2mask: [done] applying mask cleaning filter

Thank you very much for your time and assistance.

Cheers,
Chaoqing