Part is empty in tensor image

Hello,

we created a tensor image from unbiased DWI image.

dwi2tensor dwi_den_unr_pre_unbia_up.mif -mask mask_up.mif tensor_up.mif

Then we realized that sometimes there is an empty section on the first or last slide of a tensor image.
I overlaid the tensor image on the unbiased image.

The mask looks good.


We are using the ubuntu and the version of mrtrix is up to date.
Any suggestion is helpful.

Best,
Ziqian
@Lucius

OK, when you see ? as the voxel value, that means a NaN or an Inf. Presumably the tensor fit encountered negative values or something like that and taking the log caused a NaN or -Inf to be produced. What I don’t understand is how that could happen given that I thought we’d fixed all the ways that could happen…

Can I just check which version of MRtrix you’re using? Use dwi2tensor -version to get that information. This could happen if you’re running an older version…

Here is the results:

== dwi2tensor 3.0.2-2-g537bd000-dirty ==
64 bit release version, built Oct 13 2020, using Eigen 3.2.92
Author(s): Ben Jeurissen (ben.jeurissen@uantwerpen.be)
Copyright (c) 2008-2020 the MRtrix3 contributors.

This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.

Covered Software is provided under this License on an "as is"
basis, without warranty of any kind, either expressed, implied, or
statutory, including, without limitation, warranties that the
Covered Software is free of defects, merchantable, fit for a
particular purpose or non-infringing.
See the Mozilla Public License v. 2.0 for more details.

For more details, see http://www.mrtrix.org/.

I also checked the intensity of my dwi_den_unr_pre_unbia_up.mif image. The intensity values are positive.

OK, that’s the latest version – though I note the dirty label on the version string indicates the code has been modified in some way. Any reason why that might be? What does git diff report (when run within the MRtrix3 install folder)?

Did you check all volumes? A negative value in any one volume may cause trouble…

It reported these:

diff --git a/share/mrtrix3/labelconvert/fs_default.txt b/share/mrtrix3/labelconvert/fs_default.txt
index 4219d39..a0fec5b 100644
--- a/share/mrtrix3/labelconvert/fs_default.txt
+++ b/share/mrtrix3/labelconvert/fs_default.txt
@@ -17,95 +17,82 @@
 
 0     ???     Unknown                         0   0   0   0
 
-1     L.BSTS  ctx-lh-bankssts                 25  100 40  255
-2     L.CACG  ctx-lh-caudalanteriorcingulate  125 100 160 255
-3     L.CMFG  ctx-lh-caudalmiddlefrontal      100 25  0   255
-4     L.CU    ctx-lh-cuneus                   220 20  100 255
-5     L.EC    ctx-lh-entorhinal               220 20  10  255
-6     L.FG    ctx-lh-fusiform                 180 220 140 255
-7     L.IPG   ctx-lh-inferiorparietal         220 60  220 255
-8     L.ITG   ctx-lh-inferiortemporal         180 40  120 255
-9     L.ICG   ctx-lh-isthmuscingulate         140 20  140 255
-10    L.LOG   ctx-lh-lateraloccipital         20  30  140 255
-11    L.LOFG  ctx-lh-lateralorbitofrontal     35  75  50  255
-12    L.LG    ctx-lh-lingual                  225 140 140 255
-13    L.MOFG  ctx-lh-medialorbitofrontal      200 35  75  255
-14    L.MTG   ctx-lh-middletemporal           160 100 50  255
-15    L.PHIG  ctx-lh-parahippocampal          20  220 60  255
-16    L.PaCG  ctx-lh-paracentral              60  220 60  255
-17    L.POP   ctx-lh-parsopercularis          220 180 140 255
-18    L.POR   ctx-lh-parsorbitalis            20  100 50  255
-19    L.PTR   ctx-lh-parstriangularis         220 60  20  255
-20    L.PCAL  ctx-lh-pericalcarine            120 100 60  255
-21    L.PoCG  ctx-lh-postcentral              220 20  20  255
-22    L.PCG   ctx-lh-posteriorcingulate       220 180 220 255
-23    L.PrCG  ctx-lh-precentral               60  20  220 255
-24    L.PCU   ctx-lh-precuneus                160 140 180 255
-25    L.RACG  ctx-lh-rostralanteriorcingulate 80  20  140 255
-26    L.RMFG  ctx-lh-rostralmiddlefrontal     75  50  125 255
-27    L.SFG   ctx-lh-superiorfrontal          20  220 160 255
-28    L.SPG   ctx-lh-superiorparietal         20  180 140 255
-29    L.STG   ctx-lh-superiortemporal         140 220 220 255
-30    L.SMG   ctx-lh-supramarginal            80  160 20  255
-31    L.FP    ctx-lh-frontalpole              100 0   100 255
-32    L.TP    ctx-lh-temporalpole             70  70  70  255
-33    L.TTG   ctx-lh-transversetemporal       150 150 200 255
-34    L.IN    ctx-lh-insula                   255 192 32  255
-
-35    L.CER   Left-Cerebellum-Cortex          230 148 34  255
-
-36    L.TH    Left-Thalamus                   0   118 14  255
-36    L.TH    Left-Thalamus-Proper            0   118 14  255
-37    L.CA    Left-Caudate                    122 186 220 255
-38    L.PU    Left-Putamen                    236 13  176 255
-39    L.PA    Left-Pallidum                   12  48  255 255
-40    L.HI    Left-Hippocampus                220 216 20  255
-41    L.AM    Left-Amygdala                   103 255 255 255
-42    L.AC    Left-Accumbens-area             255 165 0   255
-
-43    R.TH    Right-Thalamus                  0   118 14  255
-43    R.TH    Right-Thalamus-Proper           0   118 14  255
-44    R.CA    Right-Caudate                   122 186 220 255
-45    R.PU    Right-Putamen                   236 13  176 255
-46    R.PA    Right-Pallidum                  13  48  255 255
-47    R.HI    Right-Hippocampus               220 216 20  255
-48    R.AM    Right-Amygdala                  103 255 255 255
-49    R.AC    Right-Accumbens-area            255 165 0   255
-
-50    R.BSTS  ctx-rh-bankssts                 25  100 40  255
-51    R.CACG  ctx-rh-caudalanteriorcingulate  125 100 160 255
-52    R.CMFG  ctx-rh-caudalmiddlefrontal      100 25  0   255
-53    R.CU    ctx-rh-cuneus                   220 20  100 255
-54    R.EC    ctx-rh-entorhinal               220 20  10  255
-55    R.FG    ctx-rh-fusiform                 180 220 140 255
-56    R.IPG   ctx-rh-inferiorparietal         220 60  220 255
-57    R.ITG   ctx-rh-inferiortemporal         180 40  120 255
-58    R.ICG   ctx-rh-isthmuscingulate         140 20  140 255
-59    R.LOG   ctx-rh-lateraloccipital         20  30  140 255
-60    R.LOFG  ctx-rh-lateralorbitofrontal     35  75  50  255
-61    R.LG    ctx-rh-lingual                  225 140 140 255
-62    R.MOFG  ctx-rh-medialorbitofrontal      200 35  75  255
-63    R.MTG   ctx-rh-middletemporal           160 100 50  255
-64    R.PHIG  ctx-rh-parahippocampal          20  220 60  255
-65    R.PaCG  ctx-rh-paracentral              60  220 60  255
-66    R.POP   ctx-rh-parsopercularis          220 180 140 255
-67    R.POR   ctx-rh-parsorbitalis            20  100 50  255
-68    R.PTR   ctx-rh-parstriangularis         220 60  20  255
-69    R.PCAL  ctx-rh-pericalcarine            120 100 60  255
-70    R.PoCG  ctx-rh-postcentral              220 20  20  255
-71    R.PCG   ctx-rh-posteriorcingulate       220 180 220 255
-72    R.PrCG  ctx-rh-precentral               60  20  220 255
-73    R.PCU   ctx-rh-precuneus                160 140 180 255
-74    R.RACG  ctx-rh-rostralanteriorcingulate 80  20  140 255
-75    R.RMFG  ctx-rh-rostralmiddlefrontal     75  50  125 255
-76    R.SFG   ctx-rh-superiorfrontal          20  220 160 255
-77    R.SPG   ctx-rh-superiorparietal         20  180 140 255
-78    R.STG   ctx-rh-superiortemporal         140 220 220 255
-79    R.SMG   ctx-rh-supramarginal            80  160 20  255
-80    R.FP    ctx-rh-frontalpole              100 0   100 255
-81    R.TP    ctx-rh-temporalpole             70  70  70  255
-82    R.TTG   ctx-rh-transversetemporal       150 150 200 255
-83    R.IN    ctx-rh-insula                   255 192 32  255
-
-84    R.CER   Right-Cerebellum-Cortex         230 148 34  255
-
+1     L.CACG  ctx-lh-caudalanteriorcingulate  125 100 160 255
+2     L.CMFG  ctx-lh-caudalmiddlefrontal      100 25  0   255
+3     L.CU    ctx-lh-cuneus                   220 20  100 255
+4     L.EC    ctx-lh-entorhinal               220 20  10  255
+5     L.FG    ctx-lh-fusiform                 180 220 140 255
+6     L.IPG   ctx-lh-inferiorparietal         220 60  220 255
+7     L.ITG   ctx-lh-inferiortemporal         180 40  120 255
+8     L.ICG   ctx-lh-isthmuscingulate         140 20  140 255
+9    L.LOG   ctx-lh-lateraloccipital         20  30  140 255
+10    L.LOFG  ctx-lh-lateralorbitofrontal     35  75  50  255
+11    L.LG    ctx-lh-lingual                  225 140 140 255
+12    L.MOFG  ctx-lh-medialorbitofrontal      200 35  75  255
+13    L.MTG   ctx-lh-middletemporal           160 100 50  255
+14    L.PHIG  ctx-lh-parahippocampal          20  220 60  255
+15    L.PaCG  ctx-lh-paracentral              60  220 60  255
+16    L.POP   ctx-lh-parsopercularis          220 180 140 255
+17    L.POR   ctx-lh-parsorbitalis            20  100 50  255
+18    L.PTR   ctx-lh-parstriangularis         220 60  20  255
+19    L.PCAL  ctx-lh-pericalcarine            120 100 60  255
+20    L.PoCG  ctx-lh-postcentral              220 20  20  255
+21    L.PCG   ctx-lh-posteriorcingulate       220 180 220 255
+22    L.PrCG  ctx-lh-precentral               60  20  220 255
+23    L.PCU   ctx-lh-precuneus                160 140 180 255
+24    L.RACG  ctx-lh-rostralanteriorcingulate 80  20  140 255
+25    L.RMFG  ctx-lh-rostralmiddlefrontal     75  50  125 255
+26    L.SFG   ctx-lh-superiorfrontal          20  220 160 255
+27    L.SPG   ctx-lh-superiorparietal         20  180 140 255
+28    L.STG   ctx-lh-superiortemporal         140 220 220 255
+29    L.SMG   ctx-lh-supramarginal            80  160 20  255
+30    L.TTG   ctx-lh-transversetemporal       150 150 200 255
+31    L.IN    ctx-lh-insula                   255 192 32  255
+32    L.TH    Left-Thalamus-Proper            0   118 14  255
+33   L.CA    Left-Caudate                    122 186 220 255
+34   L.PU    Left-Putamen                    236 13  176 255
+35   L.PA    Left-Pallidum                   12  48  255 255
+36   L.HI    Left-Hippocampus                220 216 20  255
+37   L.AM    Left-Amygdala                   103 255 255 255
+38   L.AC    Left-Accumbens-area             255 165 0   255
+39   L.CeC   Left-Cerebellum-Cortex           230 148 34  255
+40  R.CACG  ctx-rh-caudalanteriorcingulate  125 100 160 255
+41  R.CMFG  ctx-rh-caudalmiddlefrontal      100 25  0   255
+42   R.CU    ctx-rh-cuneus                   220 20  100 255
+43  R.EC    ctx-rh-entorhinal               220 20  10  255
+44  R.FG    ctx-rh-fusiform                 180 220 140 255
+45  R.IPG   ctx-rh-inferiorparietal         220 60  220 255
+46  R.ITG   ctx-rh-inferiortemporal         180 40  120 255
+47  R.ICG   ctx-rh-isthmuscingulate         140 20  140 255
+48  R.LOG   ctx-rh-lateraloccipital         20  30  140 255
+49  R.LOFG  ctx-rh-lateralorbitofrontal     35  75  50  255
+50  R.LG    ctx-rh-lingual                  225 140 140 255
+51   R.MOFG  ctx-rh-medialorbitofrontal      200 35  75  255
+52   R.MTG   ctx-rh-middletemporal           160 100 50  255
+53   R.PHIG  ctx-rh-parahippocampal          20  220 60  255
+54   R.PaCG  ctx-rh-paracentral              60  220 60  255
+55   R.POP   ctx-rh-parsopercularis          220 180 140 255
+56   R.POR   ctx-rh-parsorbitalis            20  100 50  255
+57   R.PTR   ctx-rh-parstriangularis         220 60  20  255
+58   R.PCAL  ctx-rh-pericalcarine            120 100 60  255
+59   R.PoCG  ctx-rh-postcentral              220 20  20  255
+60  R.PCG   ctx-rh-posteriorcingulate       220 180 220 255
+61   R.PrCG  ctx-rh-precentral               60  20  220 255
+62   R.PCU   ctx-rh-precuneus                160 140 180 255
+63   R.RACG  ctx-rh-rostralanteriorcingulate 80  20  140 255
+64   R.RMFG  ctx-rh-rostralmiddlefrontal     75  50  125 255
+65   R.SFG   ctx-rh-superiorfrontal          20  220 160 255
+66   R.SPG   ctx-rh-superiorparietal         20  180 140 255
+67   R.STG   ctx-rh-superiortemporal         140 220 220 255
+68   R.SMG   ctx-rh-supramarginal            80  160 20  255
+69   R.TTG   ctx-rh-transversetemporal       150 150 200 255
+70  R.IN    ctx-rh-insula                   255 192 32  255
+71    R.TH    Right-Thalamus-Proper           0   118 14  255
+72   R.CA    Right-Caudate                   122 186 220 255
+73   R.PU    Right-Putamen                   236 13  176 255
+74   R.PA    Right-Pallidum                  13  48  255 255
+75   R.HI    Right-Hippocampus               220 216 20  255
+76   R.AM    Right-Amygdala                  103 255 255 255
+77   R.AC    Right-Accumbens-area            255 165 0   255
+78   R.CeC   Right-Cerebellum-Cortex          230 148 34  255
+79   BS    Brain-Stem                      119 159 176 255

OK, nothing to do with the dwi2tensor code, so that rules out that as the issue. I’ll have a look through the code again to see under what conditions NaNs might be produced.

Thanks!
I checked the other volumes and there is no negative values.

OK, to help narrow down the range of possibilities, can you try running the dwi2tensor call with the -iter 0 option, and again with the -ols -iter 0 options, and check whether either of these make any difference to those NaNs…?

Not sure if this will make a difference, but could you double check the input data with interpolation disabled in the viewer?

I’ve tried both of them and there’s no difference compared to the previous picture.
But thanks to the suggestion came from @bjeurissen, we disabled the interpolation and found that these empty voxels are negative.
May I ask what is your suggestion when we come across this kind of data? Should we discard the last slide or do something else?

Thank you for the helpful suggestion. The interpolation is one of the problem, now the other problem is there are some negative value voxels in the first slide of the unbiased image. Do you have any suggestion to solve this problem?

OK, now I’m confused as to what is going on exactly…

When you say the voxels are negative, I assume you’re talking about the raw DWI? These voxels are still NaN in the DTI coefficients image, right?

If that’s the case, and neither of the alternative fitting options I suggested made any difference, then the only way I can think of that would result in NaNs would be that all volumes in the whole DWI series are negative in that region…

If that’s the case, there’s not much that we can do here: the tensor model can’t handle negative values, and in many ways NaN is the right answer. But if you want to try to ‘fix’ that, we could change this line (cmd/dwi2tensor.cpp:140) to read:

double small_intensity = 1.0e-6 * abs (dwi.maxCoeff());

That would ensure the log transform still returns non-NaN values. But there’s still no guarantee that the subsequent tensor fit will produce anything sensible. Indeed, it can’t do anything sensible in this case, but it might at least not produce NaNs…

If you want to try it, edit that file as above, run ./build again, and see if it makes any difference.

Let me try to be more clear.
When I say that voxels are negative, I’m talking about pre-processed DWI.
We did “dwidenoise”, “mrdegibbs”, “dwifslpreproc”, “dwibiascorrect” and “mrgrid” on the raw DWI data and then used this pre-processed image to achieve the DTI coefficient images.
Yes, these voxels are still NaN in the DTI coefficient image.

In the raw DWI image and the intermediate images created during these pre-processing, I also checked the region where are NaN in DTI coefficeint image. In the images after dwidenoise or mrdegibbs, the values of this region are still positive. After dwifslpreproc or dwibiascorrect, the values of this region are 0. But after mrgrid, the values of this region are negative.

I think the issue originates in dwifslpreproc, which causes the last slice to be all zeros for some reason. @rsmith: does this have anything to do with padding when there is an uneven number of slices?

Also, this is the first time you mention mrgrid… I suspect this is where the negative values get introduced… Why is this used? Are you using it to upsample before model fitting?

In all I think there is nothing wrong with dwi2tensor. Like @jdtournier mentioned, if you feed it all negative values, a nan tensor is probably the sensible thing to return.

Yes, I also just found that the problem could be from these steps.
I was using the mrgrid to upsample the voxel size to 1.3 before model fitting.

I think the issue originates in dwifslpreproc, which causes the last slice to be all zeros for some reason. @rsmith: does this have anything to do with padding when there is an uneven number of slices?

Not any more it shouldn’t. The data get padded so that topup runs with the default config file, and then the padded slice is stripped off. So output should be agnostic to that process.