Mrcalc -abs changes the intensity values

Hello all,

I realized that after doing the preprocessing steps I get some negative values in my dwi data that possibly causes the -nan values in FA maps.

1- How serious is the effect of these negative values on downstream analysis like tractography and FBA analysis?

2- I thought a quick fix would be to use the mrcalc -abs.
However, after running

mrcalc dwi_preprocessed_upsampled -abs dwi_abs.mif

I realized that the sign and values of negative pixels are both changed. For example, an original value of -3.8264 changed to 4.68824.

How that is possible?

Thank you,
Mahmoud

It’s very common, and shouldn’t be a problem. It’s typically due to the use of cubic interpolation during motion correction. It shouldn’t cause NaNs in the FA maps that we generate though, I don’t think. Were these produced using dwi2tensor & tensor2metric?

Ok, that’s worrying… I’ll have a quick look into this. Can you post the output of mrinfo on both the input and output images?

[quote=“jdtournier, post:2, topic:2656, full:true”]
Were these produced using dwi2tensor & tensor2metric?

Yes, I used the following commands:

dwi2tensor -mask mask.mif -predicted_signal predict.mif dwi_denoised_unringed_preproc_upsampled.mif tensor.mif

tensor2metric -fa FA.mif  -mask mask.mif tensor.mif
mrinfo dwi_denoised_unringed_preproc_upsampled.mif 
************************************************
Image:               "dwi_denoised_unringed_preproc_upsampled.mif"
************************************************
  Dimensions:        184 x 184 x 112 x 67
  Voxel size:        1 x 1 x 1 x 1
  Data strides:      [ -1 2 3 4 ]
  Format:            MRtrix
  Data type:         32 bit float (little endian)
  Intensity scaling: offset = 0, multiplier = 1
  Transform:               0.9952    -0.08882     0.04047      -86.88
                           0.0976       0.912     -0.3983      -77.77
                        -0.001535      0.4004      0.9164      -86.57
  command_history:   mrconvert "eddy_corrected_dataup.nii.gz" "-fslgrad" "eddy_corrected_dataup.eddy_rotated_bvecs" "dataup.bval" "dwi_denoised_unringed_preproc.mif"  (version=3.0_RC3-137-g5d6b3a6f)
                     mrresize "dwi_denoised_unringed_preproc.mif" "-vox" "1" "dwi_denoised_unringed_preproc_upsampled.mif" "-force"  (version=3.0_RC3-137-g5d6b3a6f)
  comments:          6.0.0
  dw_scheme:         0,0,0,0
  [67 entries]       0,0,0,0
                     ...
                     -0.209837188,-0.9758115573,0.06132013649,700
                     0.4602557028,0.5377692643,0.7063773117,700
  mrtrix_version:    3.0_RC3-137-g5d6b3a6f

mrinfo test.mif 
************************************************
Image:               "test.mif"
************************************************
  Dimensions:        184 x 184 x 112 x 67
  Voxel size:        1 x 1 x 1 x 1
  Data strides:      [ -1 2 3 4 ]
  Format:            MRtrix
  Data type:         32 bit float (little endian)
  Intensity scaling: offset = 0, multiplier = 1
  Transform:               0.9952    -0.08882     0.04047      -86.88
                           0.0976       0.912     -0.3983      -77.77
                        -0.001535      0.4004      0.9164      -86.57
  command_history:   mrconvert "eddy_corrected_dataup.nii.gz" "-fslgrad" "eddy_corrected_dataup.eddy_rotated_bvecs" "dataup.bval" "dwi_denoised_unringed_preproc.mif"  (version=3.0_RC3-137-g5d6b3a6f)
                     mrresize "dwi_denoised_unringed_preproc.mif" "-vox" "1" "dwi_denoised_unringed_preproc_upsampled.mif" "-force"  (version=3.0_RC3-137-g5d6b3a6f)
                     mrcalc "dwi_denoised_unringed_preproc_upsampled.mif" "-abs" "test.mif"  (version=3.0_RC3-135-g2b8e7d0c)
  comments:          6.0.0
  dw_scheme:         0,0,0,0
  [67 entries]       0,0,0,0
                     ...
                     -0.209837188,-0.9758115573,0.06132013649,700
                     0.4602557028,0.5377692643,0.7063773117,700
  mrtrix_version:    3.0_RC3-135-g2b8e7d0c

Ok, nothing suspicious there. I’ll take a look into the mrcalc -abs issue.

Regarding the NaN issue: were there any NaNs in the raw DWI or DT images for the problematic voxels?

Hi Donald,

Have you had the chance to look at the mrinfo outputs?

Thanks,
Mahmoud

I looked at pre-processed DWI and tensor.mif. I could see negative values in (some volumes of ) pre-processed DWI and tensor.mif at locations that there is -nan in FA map.

Would you need any other info for mrcalc -abs issue?

BTW, I guess that the negative values got introduced into dwi after the up-sampling step using mrresize.

I used mrcalc dwi_denoised_unringed_preproc.mif 0 -lt - | mrstats - and couldn’t see any volume with negative values but

mrcalc dwi_denoised_unringed_preproc_upsampled.mif 0 -lt - | mrstats -

shows that all volumes have different number of negative points. (all volumes have negative values at the borders of image but some have additional negative points in or close to brain area.)

Yes, mrresize uses cubic interpolation by default, which can easily introduce negative values due to its ability to over/undershoot. Nothing suspicious there. :+1:

Ok, that helps narrow down the issue. Negative values in the DWI are non-physical, but there are safeguards in place to deal with these in the tensor fit. It looks like these are working, otherwise you’d get NaNs in your tensor map.

BTW, you’d expect to see negative values in the tensor coefficients in any case, at least for the off-diagonal elements (the last 3 volumes). It’s a bit more tricky if any diagonal elements (the first 3 volumes) are negative, that would clearly be non-physical.

But from what you show, the issue occurs in the tensor to FA computation. The problem is I can’t see how that code can possibly produce a NaN…

What exact version of MRtrix3 are you running (tensor2metric -version)?

Also, any chance you could provide the values of the tensor coefficients at the problematic voxel? You can do that by creating a single-voxel ROI in mrview and using e.g. mrstat -mask ROI.mif -output mean fa.mif.

1 Like

I can’t reproduce this behaviour – everything seems to work fine on my system… Is your installation fully up to date? Maybe if you have data where the issue happens every time, you can send them to me so I can take a look?

I also note you marked my previous post as the solution. What was it that fixed it for you?

Thanks for your note, Donald.
It was taking too much time so I just decided to get rid of the negative values in dwi images (by masking the negative values) and after that, I don’t see -nan values.