Dwipreproc rpe_all

Dear all

I’ve this problem running dwipreproc

$ dwipreproc auto-dti_APPA.mif auto-dti_preproc.mif -rpe_all -pe_dir PA -eddy_options "--slm=linear "
$ dwipreproc : [ERROR] Unable to determine matching reversed phase-encode direction volume for DWI volume 2

for note

  • I’ve 2 DWI volumes AP and PA and I try to use dwipreproc
- $ mrinfo auto-dti_AP.mif
************************************************
Image:               "auto-dti_AP.mif"
************************************************
  Dimensions:        128 x 128 x 24 x 33
  Voxel size:        1.75 x 1.75 x 2 x ?
  Data strides:      [ -1 -2 3 4 ]
  Format:            MRtrix
  Data type:         unsigned 16 bit integer (little endian)
  Intensity scaling: offset = 0, multiplier = 1.78095
  Transform:               0.9983    -0.05261    -0.02375      -106.3
                          0.05303      0.9984     0.01736      -97.71
                           0.0228    -0.01859      0.9996      -27.04
  EchoTime:          0.093387
  FlipAngle:         90
  RepetitionTime:    2.8905
  command_history:   mrconvert "." "auto-dti_AP.mif"  (version=3.0_RC3-214-g1b818fca)
  comments:          STATE COSMIN DANIEL    (10900165) [MR] DTI_32_AP
                     study: FOSSE POST [ ORIGINAL PRIMARY M_SE M SE ]
                     DOB: 02/08/1996
                     DOS: 16/10/2019 09:45:35
  dw_scheme:         0,0,0,0
  [33 entries]       -0.023748479783535004,0.017358968034386635,0.99956727027893066,1000
                     ...
                     -0.49237087368965149,-0.40296009182929993,0.77148574590682983,1000
                     -0.98746919631958008,-0.019199294969439507,0.15663017332553864,1000
  mrtrix_version:    3.0_RC3-214-g1b818fca

please help

thanks +++

Tim
see appended

I am also seeing a similar problem.

dwipreproc: [ERROR] Unable to determine matching reversed phase-encode direction volume for DWI volume 1.

We are processing about 100 subjects, and seeing this on about half of the subject. Maybe there is something wrong with the same bvecs are rounded (for matching?)

The below is the entire output from dwipreproc.

$ dwipreproc -eddy_options '  --repol --data_is_shelled --slm=linear --niter=5' -rpe_all -pe_dir AP dwi_denoise_degibbs.mif dwi_denoise_degibbs_eddy.mif -eddyqc_all ./eddyqc 
dwipreproc: 
dwipreproc: Note that this script makes use of commands / algorithms that have relevant articles for citation; INCLUDING FROM EXTERNAL SOFTWARE PACKAGES. Please consult the help page (-help option) for more information.
dwipreproc: 
dwipreproc: Generated temporary directory: /home/hayashis/Downloads/dwipreproc-tmp-2XWKCY/
Command:  mrconvert /home/hayashis/Downloads/dwi_denoise_degibbs.mif /home/hayashis/Downloads/dwipreproc-tmp-2XWKCY/dwi.mif
dwipreproc: Changing to temporary directory (/home/hayashis/Downloads/dwipreproc-tmp-2XWKCY/)
matching index1:0
index2:72
dwi_num_volumnes:144
grad1:[0.0, 0.0, 0.0, 0.0]
grad2:[0.0, 0.0, 0.0, 0.0]
matching index1:1
index2:72
matching index1:1
index2:73
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[-0.9999565608, -0.00707591008, -0.006066959893, 989.999975]
matching index1:1
index2:74
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[0.0, 0.9999821093, -0.005981729776, 1005.000019]
matching index1:1
index2:75
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[0.02504331829, 0.655557579, -0.7547298145, 989.9999815]
matching index1:1
index2:76
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[-0.5891150802, -0.7704021296, -0.2437703448, 1000.00001]
matching index1:1
index2:77
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[0.2359168994, -0.5314917603, -0.8135476171, 989.9999856]
matching index1:1
index2:78
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[0.8938854181, -0.2656021845, -0.3611431002, 989.9999023]
matching index1:1
index2:79
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[-0.7988092416, 0.1353889127, -0.5861515486, 984.9999723]
matching index1:1
index2:80
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[-0.2328688083, 0.9328112714, -0.2750186357, 999.9999758]
matching index1:1
index2:81
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[0.0, 0.0, 0.0, 0.0]
matching index1:1
index2:82
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[-0.9369556079, 0.1467639713, -0.3171348696, 989.9999224]
matching index1:1
index2:83
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[-0.5038913499, -0.8473682422, 0.1675128941, 999.9999959]
matching index1:1
index2:84
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[-0.3449192932, -0.8516358114, 0.3946481039, 1000.000005]
matching index1:1
index2:85
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[-0.4567484553, -0.6371757977, 0.6207961433, 995.0000024]
matching index1:1
index2:86
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[0.4876230197, -0.3965021538, -0.77782378, 985.0000654]
matching index1:1
index2:87
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[0.6167598838, 0.6786728363, -0.3987611153, 995.0000406]
matching index1:1
index2:88
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[0.5787692745, -0.111476095, 0.8078361264, 984.9999731]
matching index1:1
index2:89
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[0.8250462628, -0.526606335, -0.20490103, 994.999948]
matching index1:1
index2:90
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[0.0, 0.0, 0.0, 0.0]
matching index1:1
index2:91
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[-0.895791564, -0.04728361023, 0.4419521854, 989.9999264]
matching index1:1
index2:92
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[-0.2901141359, -0.5482568765, 0.7843775784, 989.9999912]
matching index1:1
index2:93
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[-0.1150200032, -0.9645821768, 0.2373849679, 999.9999343]
matching index1:1
index2:94
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[0.8000754531, 0.4099099244, 0.4380104144, 990.0000451]
matching index1:1
index2:95
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[-0.5118810034, 0.8430330316, -0.1651458324, 999.9999623]
matching index1:1
index2:96
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[0.7906338, 0.1597335613, 0.5910866127, 984.9998456]
matching index1:1
index2:97
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[-0.9491868588, -0.2403454029, -0.2031708503, 995.0000057]
matching index1:1
index2:98
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[-0.2323098361, 0.788614104, -0.5693153213, 994.9999755]
matching index1:1
index2:99
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[0.0, 0.0, 0.0, 0.0]
matching index1:1
index2:100
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[0.0199764243, -0.1942943657, 0.9807398442, 984.9999755]
matching index1:1
index2:101
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[-0.2158380864, -0.9577605581, -0.1900227191, 1005.00003]
matching index1:1
index2:102
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[-0.7720274608, -0.6089869488, -0.1819574013, 1000.000082]
matching index1:1
index2:103
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[0.1600511666, 0.3630185119, -0.9179331044, 985.0000045]
matching index1:1
index2:104
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[0.1465623015, 0.7371672658, 0.6596240702, 995.000089]
matching index1:1
index2:105
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[-0.8868907819, 0.4233542444, -0.1849214015, 994.9999711]
matching index1:1
index2:106
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[0.5635648224, 0.238691741, 0.7908355985, 985.0000513]
matching index1:1
index2:107
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[0.3819320242, 0.1494071053, -0.9120336867, 984.9999791]
matching index1:1
index2:108
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[0.0, 0.0, 0.0, 0.0]
matching index1:1
index2:109
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[0.3068391819, -0.2063414547, 0.9291248143, 984.9999114]
matching index1:1
index2:110
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[0.3331855467, -0.136038986, -0.9329955979, 980.000041]
matching index1:1
index2:111
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[0.9618037623, -0.271306476, -0.03641866029, 995.0000652]
matching index1:1
index2:112
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[0.9596650444, 0.2115071084, -0.1852235019, 995.0000323]
matching index1:1
index2:113
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[-0.4507181272, -0.8906774367, -0.05955563409, 1004.9999]
matching index1:1
index2:114
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[0.7701517354, 0.6328940996, -0.07944408814, 999.9999974]
matching index1:1
index2:115
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[-0.7100332052, 0.4149750876, -0.568901155, 990.0000912]
matching index1:1
index2:116
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[0.695902611, 0.02958313109, -0.7175265809, 984.999929]
matching index1:1
index2:117
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[0.0, 0.0, 0.0, 0.0]
matching index1:1
index2:118
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[-0.6814672474, 0.5352043605, 0.4991579742, 994.9999641]
matching index1:1
index2:119
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[0.1415655565, -0.7314580434, -0.6670294776, 995.0000668]
matching index1:1
index2:120
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[0.7410058748, 0.395233472, -0.5428635152, 989.9999014]
matching index1:1
index2:121
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[0.102484551, 0.8276202428, -0.5518529247, 995.0000604]
matching index1:1
index2:122
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[-0.5838748698, -0.602538693, -0.5440930617, 995.0000391]
matching index1:1
index2:123
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[0.08727772394, -0.3418323641, -0.9356993287, 985.0000316]
matching index1:1
index2:124
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[0.5500507616, -0.7966462155, -0.2505972206, 999.9999052]
matching index1:1
index2:125
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[-0.8371042842, -0.4640292058, 0.2897124669, 994.9999444]
matching index1:1
index2:126
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[0.0, 0.0, 0.0, 0.0]
matching index1:1
index2:127
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[-0.3630114183, -0.5680458523, -0.7386112779, 990.000008]
matching index1:1
index2:128
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[0.1836361666, 0.3995099241, 0.8981478602, 989.9999143]
matching index1:1
index2:129
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[0.7176295254, -0.6964236223, -0.001415149956, 999.999908]
matching index1:1
index2:130
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[-0.4329999453, 0.6878464922, 0.5825617997, 994.9999697]
matching index1:1
index2:131
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[-0.501827032, 0.6961205197, -0.5134061277, 995.0001157]
matching index1:1
index2:132
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[0.1710452303, -0.5161890434, 0.8392213061, 989.9999823]
matching index1:1
index2:133
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[-0.4636260654, 0.4303399126, -0.7745052816, 990.0000912]
matching index1:1
index2:134
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[-0.3838653298, -0.8141389556, -0.4356893039, 994.9999836]
matching index1:1
index2:135
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[0.0, 0.0, 0.0, 0.0]
matching index1:1
index2:136
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[0.7150368331, -0.2536229066, -0.6514581711, 985.0000991]
matching index1:1
index2:137
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[-0.2593905425, 0.8880150047, 0.3796655079, 999.9999268]
matching index1:1
index2:138
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[-8.47e-05, 0.08298241603, 0.996551008, 984.9999393]
matching index1:1
index2:139
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[-0.03643157823, -0.9059204154, -0.4218778746, 999.9999357]
matching index1:1
index2:140
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[-0.5709425598, -0.3105253761, 0.7599990686, 990.0000726]
matching index1:1
index2:141
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[0.2829893494, 0.1518946569, 0.947019029, 985.0000241]
matching index1:1
index2:142
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[-0.719800704, 0.6140916799, -0.323694849, 994.999854]
matching index1:1
index2:143
dwi_num_volumnes:144
grad1:[-0.9999821093, -2.050993384e-10, -0.005981729776, 1005.000019]
grad2:[-0.2656599953, 0.9609300164, 0.07770630932, 1004.999944]
dwipreproc: [ERROR] Unable to determine matching reversed phase-encode direction volume for DWI volume 1
dwipreproc: Changing back to original directory (/home/hayashis/Downloads)
dwipreproc: Contents of temporary directory kept, location: /home/hayashis/Downloads/dwipreproc-tmp-2XWKCY/

Determination of volumes with matching diffusion sensitisation directions is done by this code. So any potential source of discrepancy between the gradient tables stored in the headers of the AP and PA DWI series that exceeds the thresholds there will result in dwipreproc not being able to proceed.

Because mrinfo truncates the contents of multi-line header entries, what really needs to be provided is the output of: “mrinfo auto-dti_APPA.mif -dwgrad”.

Rob

Dear Rob
thanks a lot, it actually worked
but could you help me to create an ouput and implement it in the dwipreproc command ?
best
TJ

@Timothee_Jacquesson

I made a script like this to check it.

#!/usr/bin/python

def grads_match(one, two):
  # Dot product between gradient directions
  # First, need to check for zero-norm vectors:
  # - If both are zero, skip this check
  # - If one is zero and the other is not, volumes don't match
  # - If neither is zero, test the dot product
  if any([val for val in one[0:3]]):
    if not any([val for val in two[0:3]]):
      return False
    dot_product = one[0]*two[0] + one[1]*two[1] + one[2]*two[2]
    if abs(dot_product) < 0.999:
      return False
  elif any([val for val in two[0:3]]):
    return False
  # b-value
  if abs(one[3]-two[3]) > 10.0:
    return False
  return True

#output from mrinfo dwi.mif -dwgrad
with open("grad.txt") as f:
    content = f.readlines()
content = [x.strip() for x in content] 
#print(content)

print(len(content))
one = [float(i) for i in content[1].split()]
two = [float(i) for i in content[73].split()]
print(one)
print(two)
print(grads_match(one, two))

@rsmith

So for my case, it looks like the dot product is all >0.999, but it’s failing to match because of a few (2 our of 72 pairs) bvalue differences being >10

[-0.999982, -2.051e-10, -0.00598173, 1005.0]
[-0.999963, -0.00606606, -0.00606606, 990.0]

Could the b-value difference threshold be configurable? Also, I think <10 is a bit too strict as this code is simply making sure that the gradient table is lined up correctly… I am not an expert but maybe <50 would be ok for this?

Or… do you suggest I round the bvecs before running mrtrix?

Okay, that makes sense now.

For a quick fix, you can either:

  • Increase the numerical threshold for the b-value comparison within the dwipreproc code;

  • Edit your gradient table so that there is no fluctuation between volumes corresponding to the same nominal b-value.

Longer-term more robust solution has been listed as an issue on GitHub.