Generate FA value and do fiber tracking from DICOM data

Dear MRtrix3 community,

Is there any method to generate “Nifti” ,“bvalues” and “bvecs” from “.dcm” file?
I wanna to use a series of DICOM data to do fiber tracking and FA value generation. However, when I produce a mask file though the command “$ dwi2mask S186513/ S186513_mask.nii”, it has an error:

brain@neurodebian:/media/windows-share/PPMI_Data$ dwi2mask S186513/ S186513_mask.nii
dwi2mask: [done] scanning DICOM folder "S186513/"
dwi2mask: [100%] reading DICOM series "AX T2 AC-PC line Entire Brain"
dwi2mask: [100%] preloading data for "DE-IDENTIFIED (3008) [MR] AX T2 AC-PC line Entire Brain"
dwi2mask: [100%] finding min/max of "mean b=0 image"
dwi2mask: [done] optimising threshold
dwi2mask: [100%] thresholding
dwi2mask: [done] computing dwi brain mask
dwi2mask: [done] applying mask cleaning filter
*** Error in `dwi2mask’: free(): invalid pointer: 0x000000000129c6b0 ***
Aborted

Do you have any ideas about this issue?

But the file “S186513_mask.nii” exist in the folder. I can’t believe it.
Also, I think it can not produce the “b values” and “b vecs”.

Thanks,
Chaoqing
MRtrix beginner

Yes, this command should do it:

$ mrconvert DICOM_folder/ data.nii -export_grad_fsl bvecs bvals

OK, if there’s an overt crash like this, we should fix it. Can I just check that your installation is up to date? What does dwi2mask -version report? Also, what OS are you running on?

The output file is typically created before processing even starts, and the data either gets written to it directly during processing (via memory-mapping), or in one go at the end of processing (depending on the type of filesystem the file resides on). So it is completely expected for it to be present. What’s more important is whether the crash happened after the data got written to file. The ‘applying mask cleaning filter’ step is the last thing to happen, and completed successfully, so there’s a good chance the output might be OK. Does the image look sensible when viewed in MRView? If you run the command again with the -debug option and post the full output here, we’ll have a better idea of exactly where the problem occurred.

Not sure what you mean here… dwi2mask is not designed to extract the bvals & bvecs - although it does need that information to run. It would not even have started processing if it hadn’t found that information (in your case this was read directly from the DICOM headers). Given the output you’re showing, it clearly got quite a long way before crashing, so clearly it was able to find that information.

Hi,

OK, if there’s an overt crash like this, we should fix it. Can I just check that your installation is up to date? What does dwi2mask -version report? Also, what OS are you running on?

My OS: NeuroDebian 8.00 (64bit), I run virtual machine Debian 64bit in Oracle VM VirtualBox on windows 10.
brain@neurodebian:/media/windows-share/PPMI_Data$ dwi2mask -version
== dwi2mask 0.3.15-266-g2bf78387 ==
64 bit release version, built Sep 20 2016, using Eigen 3.2.2
Author(s): David Raffelt (david.raffelt@florey.edu.au) and Thijs Dhollander (thijs.dhollander@gmail.com)
Copyright (c) 2008-2016 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 Mozilla Public License, version 2.0

MRtrix is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Does the image look sensible when viewed in MRView? If you run the command again with the -debug option and post the full output here, we’ll have a better idea of exactly where the problem occurred.
When viewed in MRview:

run the command again with the -debug option(It is too long so I just pos a part of the output here):

dwi2mask: [done] optimising threshold
dwi2mask: [DEBUG] initialising threads...
dwi2mask: [DEBUG] launching 4 threads "loop threads"...
dwi2mask: [  0%] thresholding... 
dwi2mask: [DEBUG] waiting for completion of threads "loop threads"...
dwi2mask: [100%] thresholding... 
dwi2mask: [DEBUG] threads "loop threads" completed OK
dwi2mask: [100%] thresholding
dwi2mask: [ .  ] computing dwi brain mask... 
dwi2mask: [DEBUG] deleting scratch buffer for image "scratch image"...
dwi2mask: [DEBUG] image "scratch image" unloaded
dwi2mask: [DEBUG] deleting scratch buffer for image "mean b=0 image"...
dwi2mask: [DEBUG] image "mean b=0 image" unloaded
dwi2mask: [DEBUG] sanitising image information...
dwi2mask: [DEBUG] allocating scratch buffer for image "temporary mask"...
dwi2mask: [DEBUG] image "temporary mask" loaded
dwi2mask: [DEBUG] image "temporary mask" initialised with strides = [ -1 -512 262144 ], start = 262143, using direct IO
dwi2mask: [DEBUG] median adapter for image "DWI mask" initialised with extent [ 3 3 3 ]
dwi2mask: [DEBUG] initialising threads...
dwi2mask: [DEBUG] launching 4 threads "loop threads"...
dwi2mask: [DEBUG] waiting for completion of threads "loop threads"...
dwi2mask: [DEBUG] threads "loop threads" completed OK
dwi2mask: [   .] computing dwi brain mask... 
dwi2mask: [DEBUG] sanitising image information...
dwi2mask: [DEBUG] allocating scratch buffer for image "scratch image"...
dwi2mask: [DEBUG] image "scratch image" loaded
dwi2mask: [DEBUG] image "scratch image" initialised with strides = [ -1 -512 262144 ], start = 262143, using direct IO
dwi2mask: [DEBUG] deleting scratch buffer for image "scratch image"...
dwi2mask: [DEBUG] image "scratch image" unloaded
dwi2mask: [  . ] computing dwi brain mask... 
dwi2mask: [DEBUG] sanitising image information...
dwi2mask: [DEBUG] allocating scratch buffer for image "scratch image"...
dwi2mask: [DEBUG] image "scratch image" loaded
dwi2mask: [DEBUG] image "scratch image" initialised with strides = [ -1 -512 262144 ], start = 262143, using direct IO
dwi2mask: [DEBUG] deleting scratch buffer for image "scratch image"...
dwi2mask: [DEBUG] image "scratch image" unloaded
dwi2mask: [  . ] computing dwi brain mask... 
dwi2mask: [DEBUG] deleting scratch buffer for image "temporary mask"...
dwi2mask: [DEBUG] image "temporary mask" unloaded
dwi2mask: [done] computing dwi brain mask
dwi2mask: [DEBUG] deleting scratch buffer for image "DWI mask"...
dwi2mask: [DEBUG] image "DWI mask" unloaded
dwi2mask: [INFO] creating image "S186513_mask1.nii"...
dwi2mask: [DEBUG] sanitising image information...
dwi2mask: [DEBUG] creating empty file "S186513_mask1.nii"
dwi2mask: [DEBUG] resizing file "S186513_mask1.nii" to 21234016
dwi2mask: [DEBUG] sanitising image information...
dwi2mask: [DEBUG] memory-mapping file "S186513_mask1.nii"...
dwi2mask: [DEBUG] "S186513_mask1.nii" appears to reside on a networked filesystem - using delayed write-back
dwi2mask: [DEBUG] file "S186513_mask1.nii" held in RAM at 0x75d6e0, size 21233664
dwi2mask: [DEBUG] image "S186513_mask1.nii" loaded
dwi2mask: [DEBUG] image "S186513_mask1.nii" initialised with strides = [ -1 -512 262144 ], start = 262143, using indirect IO
dwi2mask: [.   ] applying mask cleaning filter... 
dwi2mask: [DEBUG] sanitising image information...
dwi2mask: [DEBUG] allocating scratch buffer for image "temporary input mask"...
dwi2mask: [DEBUG] image "temporary input mask" loaded
dwi2mask: [DEBUG] image "temporary input mask" initialised with strides = [ -1 -512 262144 ], start = 262143, using direct IO
dwi2mask: [DEBUG] sanitising image information...
dwi2mask: [DEBUG] allocating scratch buffer for image "temporary output mask"...
dwi2mask: [DEBUG] image "temporary output mask" loaded
dwi2mask: [DEBUG] image "temporary output mask" initialised with strides = [ -1 -512 262144 ], start = 262143, using direct IO
dwi2mask: [DEBUG] sanitising image information...
dwi2mask: [DEBUG] allocating scratch buffer for image "temporary mask"...
dwi2mask: [DEBUG] image "temporary mask" loaded
dwi2mask: [DEBUG] image "temporary mask" initialised with strides = [ -1 -512 262144 ], start = 262143, using direct IO
dwi2mask: [DEBUG] sanitising image information...
dwi2mask: [DEBUG] allocating scratch buffer for image "deletion mask"...
dwi2mask: [DEBUG] image "deletion mask" loaded
dwi2mask: [DEBUG] image "deletion mask" initialised with strides = [ -1 -512 262144 ], start = 262143, using direct IO
dwi2mask: [DEBUG] sanitising image information...
dwi2mask: [DEBUG] allocating scratch buffer for image "scratch image"...
dwi2mask: [DEBUG] image "scratch image" loaded
dwi2mask: [DEBUG] image "scratch image" initialised with strides = [ -1 -512 262144 ], start = 262143, using direct IO
dwi2mask: [DEBUG] sanitising image information...
dwi2mask: [DEBUG] allocating scratch buffer for image "scratch image"...
dwi2mask: [DEBUG] image "scratch image" loaded
dwi2mask: [DEBUG] image "scratch image" initialised with strides = [ -1 -512 262144 ], start = 262143, using direct IO
dwi2mask: [DEBUG] deleting scratch buffer for image "scratch image"...
dwi2mask: [DEBUG] image "scratch image" unloaded
dwi2mask: [DEBUG] sanitising image information...
dwi2mask: [DEBUG] allocating scratch buffer for image "scratch image"...
dwi2mask: [DEBUG] image "scratch image" loaded
dwi2mask: [DEBUG] image "scratch image" initialised with strides = [ -1 -512 262144 ], start = 262143, using direct IO
dwi2mask: [DEBUG] deleting scratch buffer for image "scratch image"...
dwi2mask: [DEBUG] image "scratch image" unloaded
dwi2mask: [DEBUG] deleting scratch buffer for image "scratch image"...
dwi2mask: [DEBUG] image "scratch image" unloaded
dwi2mask: [DEBUG] sanitising image information...
dwi2mask: [DEBUG] allocating scratch buffer for image "largest component"...
dwi2mask: [DEBUG] image "largest component" loaded
dwi2mask: [DEBUG] image "largest component" initialised with strides = [ -1 -512 262144 ], start = 262143, using direct IO
dwi2mask: [DEBUG] sanitising image information...
dwi2mask: [DEBUG] allocating scratch buffer for image "scratch image"...
dwi2mask: [DEBUG] image "scratch image" loaded
dwi2mask: [DEBUG] image "scratch image" initialised with strides = [ -1 -512 262144 ], start = 262143, using direct IO
dwi2mask: [DEBUG] deleting scratch buffer for image "scratch image"...
dwi2mask: [DEBUG] image "scratch image" unloaded
dwi2mask: [DEBUG] sanitising image information...
dwi2mask: [DEBUG] allocating scratch buffer for image "scratch image"...
dwi2mask: [DEBUG] image "scratch image" loaded
dwi2mask: [DEBUG] image "scratch image" initialised with strides = [ -1 -512 262144 ], start = 262143, using direct IO
dwi2mask: [DEBUG] sanitising image information...
dwi2mask: [DEBUG] allocating scratch buffer for image "scratch image"...
dwi2mask: [DEBUG] image "scratch image" loaded
dwi2mask: [DEBUG] image "scratch image" initialised with strides = [ -1 -512 262144 ], start = 262143, using direct IO
dwi2mask: [DEBUG] deleting scratch buffer for image "scratch image"...
dwi2mask: [DEBUG] image "scratch image" unloaded
dwi2mask: [DEBUG] sanitising image information...
dwi2mask: [DEBUG] allocating scratch buffer for image "scratch image"...
dwi2mask: [DEBUG] image "scratch image" loaded
dwi2mask: [DEBUG] image "scratch image" initialised with strides = [ -1 -512 262144 ], start = 262143, using direct IO
dwi2mask: [DEBUG] deleting scratch buffer for image "scratch image"...
dwi2mask: [DEBUG] image "scratch image" unloaded
dwi2mask: [DEBUG] sanitising image information...
dwi2mask: [DEBUG] allocating scratch buffer for image "scratch image"...
dwi2mask: [DEBUG] image "scratch image" loaded
dwi2mask: [DEBUG] image "scratch image" initialised with strides = [ -1 -512 262144 ], start = 262143, using direct IO
dwi2mask: [DEBUG] deleting scratch buffer for image "scratch image"...
dwi2mask: [DEBUG] image "scratch image" unloaded
dwi2mask: [DEBUG] deleting scratch buffer for image "scratch image"...
dwi2mask: [DEBUG] image "scratch image" unloaded
dwi2mask: [DEBUG] deleting scratch buffer for image "largest component"...
dwi2mask: [DEBUG] image "largest component" unloaded
dwi2mask: [DEBUG] deleting scratch buffer for image "deletion mask"...
dwi2mask: [DEBUG] image "deletion mask" unloaded
dwi2mask: [DEBUG] sanitising image information...
dwi2mask: [DEBUG] allocating scratch buffer for image "deletion mask"...
dwi2mask: [DEBUG] image "deletion mask" loaded
dwi2mask: [DEBUG] image "deletion mask" initialised with strides = [ -1 -512 262144 ], start = 262143, using direct IO
dwi2mask: [DEBUG] sanitising image information...
dwi2mask: [DEBUG] allocating scratch buffer for image "scratch image"...
dwi2mask: [DEBUG] image "scratch image" loaded
dwi2mask: [DEBUG] image "scratch image" initialised with strides = [ -1 -512 262144 ], start = 262143, using direct IO
dwi2mask: [DEBUG] sanitising image information...
dwi2mask: [DEBUG] allocating scratch buffer for image "scratch image"...
dwi2mask: [DEBUG] image "scratch image" loaded
dwi2mask: [DEBUG] image "scratch image" initialised with strides = [ -1 -512 262144 ], start = 262143, using direct IO
dwi2mask: [DEBUG] deleting scratch buffer for image "scratch image"...
dwi2mask: [DEBUG] image "scratch image" unloaded
dwi2mask: [DEBUG] deleting scratch buffer for image "scratch image"...
dwi2mask: [DEBUG] image "scratch image" unloaded
dwi2mask: [DEBUG] sanitising image information...
dwi2mask: [DEBUG] allocating scratch buffer for image "largest component"...
dwi2mask: [DEBUG] image "largest component" loaded
dwi2mask: [DEBUG] image "largest component" initialised with strides = [ -1 -512 262144 ], start = 262143, using direct IO
dwi2mask: [DEBUG] sanitising image information...
dwi2mask: [DEBUG] allocating scratch buffer for image "scratch image"...
dwi2mask: [DEBUG] image "scratch image" loaded
dwi2mask: [DEBUG] image "scratch image" initialised with strides = [ -1 -512 262144 ], start = 262143, using direct IO
dwi2mask: [DEBUG] deleting scratch buffer for image "scratch image"...
dwi2mask: [DEBUG] image "scratch image" unloaded
dwi2mask: [DEBUG] sanitising image information...
dwi2mask: [DEBUG] allocating scratch buffer for image "scratch image"...
dwi2mask: [DEBUG] image "scratch image" loaded
dwi2mask: [DEBUG] image "scratch image" initialised with strides = [ -1 -512 262144 ], start = 262143, using direct IO
dwi2mask: [DEBUG] sanitising image information...
dwi2mask: [DEBUG] allocating scratch buffer for image "scratch image"...
dwi2mask: [DEBUG] image "scratch image" loaded
dwi2mask: [DEBUG] image "scratch image" initialised with strides = [ -1 -512 262144 ], start = 262143, using direct IO
dwi2mask: [DEBUG] deleting scratch buffer for image "scratch image"...
dwi2mask: [DEBUG] image "scratch image" unloaded
dwi2mask: [DEBUG] sanitising image information...
dwi2mask: [DEBUG] allocating scratch buffer for image "scratch image"...
dwi2mask: [DEBUG] image "scratch image" loaded
dwi2mask: [DEBUG] image "scratch image" initialised with strides = [ -1 -512 262144 ], start = 262143, using direct IO
dwi2mask: [DEBUG] deleting scratch buffer for image "scratch image"...
dwi2mask: [DEBUG] image "scratch image" unloaded
dwi2mask: [DEBUG] deleting scratch buffer for image "scratch image"...
dwi2mask: [DEBUG] image "scratch image" unloaded
dwi2mask: [DEBUG] deleting scratch buffer for image "largest component"...
dwi2mask: [DEBUG] image "largest component" unloaded
dwi2mask: [DEBUG] deleting scratch buffer for image "deletion mask"...
dwi2mask: [DEBUG] image "deletion mask" unloaded
dwi2mask: [DEBUG] sanitising image information...
dwi2mask: [DEBUG] allocating scratch buffer for image "scratch image"...
dwi2mask: [DEBUG] image "scratch image" loaded
dwi2mask: [DEBUG] image "scratch image" initialised with strides = [ -1 -512 262144 ], start = 262143, using direct IO
dwi2mask: [DEBUG] deleting scratch buffer for image "scratch image"...
dwi2mask: [DEBUG] image "scratch image" unloaded
dwi2mask: [DEBUG] deleting scratch buffer for image "temporary mask"...
dwi2mask: [DEBUG] image "temporary mask" unloaded
dwi2mask: [  . ] applying mask cleaning filter... 
dwi2mask: [DEBUG] deleting scratch buffer for image "temporary output mask"...
dwi2mask: [DEBUG] image "temporary output mask" unloaded
dwi2mask: [DEBUG] deleting scratch buffer for image "temporary input mask"...
dwi2mask: [DEBUG] image "temporary input mask" unloaded
dwi2mask: [done] applying mask cleaning filter
dwi2mask: [INFO] writing back contents of mapped file "S186513_mask1.nii"...
dwi2mask: [DEBUG] image "S186513_mask1.nii" unloaded
dwi2mask: [DEBUG] deleting scratch buffer for image "brain mask"...
dwi2mask: [DEBUG] image "brain mask" unloaded
*** Error in `dwi2mask': free(): invalid pointer: 0x0000000000755600 ***
Aborted

Moreover, when I follow the command:mrconvert S186513/ S186513.nii -export_grad_fs S186513.bvecs S186513.bvals , it does generate S186513.nii, S186513_bvals and S186513_bvecs files. However, when I view the context:

Is there anything wrong with my DICOM data? I download it from http://www.ppmi-info.org/ a database of Parkinson’s Disease.

Then I test the command in the another data that comes from a hospital, the output shows:
$ mrconvert 48310001/ 48310001.nii -export_grad_fs 48310001.bvecs 48310001.bvals
mrconvert: [done] scanning DICOM folder “48310001/”
Select series (‘q’ to abort):
0 - 160 MR images 10:48:21 t1_mprage_sag_p2_iso (*tfl3d1_16ns) [11]
1 - 72 MR images 10:48:56 ep2d_diff_mddw_20_p2 (*ep_b0) [12]
2 - 25 MR images 10:53:02 ep2d_diff_mddw_20_p2_ADC (*ep_b0_1000) [13]
3 - 25 MR images 10:53:02 ep2d_diff_mddw_20_p2_TRACEW (*ep_b1000t) [14]
4 - 25 MR images 10:53:02 ep2d_diff_mddw_20_p2_FA (*ep_b0_1000) [15]
5 - 25 MR images 10:53:02 ep2d_diff_mddw_20_p2_ColFA (?) [16]
? 0
mrconvert: [100%] reading DICOM series “t1_mprage_sag_p2_iso”
mrconvert: [ERROR] no gradient information found within image “48310001.nii”

I don’t know why these happen, I think, maybe there have something wrong with my original DICOM data.

Thanks for your time. and Thanks again for your patient assistance.

best,
Chaoqing

Most likely… It looks like you have a single b-zero volume in your dataset. What does mrinfo report for your image?

I notice the data states that it’s been anonymised. That process will often strip out non-standard DICOM tags from the image headers, which can be a problem if the DW gradient information is stored in those fields. Not sure whether that is the problem, but I wouldn’t be surprised.

For the mrconvert command failing, this is because the series you’ve selected (0) corresponds to the T1, not the diffusion - there is no gradient information for these data. You need to select the second series (number 1).

Most likely… It looks like you have a single b-zero volume in your dataset. What does mrinfo report for your image?

the result as shown, it seems missing a dimension:

$ mrinfo S186513/
mrinfo: [done] scanning DICOM folder “S186513/”
mrinfo: [100%] reading DICOM series “AX T2 AC-PC line Entire Brain”
************************************************
Image: “DE-IDENTIFIED (3008) [MR] AX T2 AC-PC line Entire Brain”
************************************************
Dimensions: 512 x 512 x 81
Voxel size: 0.4883 x 0.4883 x 2
Data strides: [ -1 -2 3 ]
Format: DICOM
Data type: unsigned 16 bit integer (little endian)
Intensity scaling: offset = 0, multiplier = 1
Transform: 1 -0 0.0003357 -122.6
-0 1 -0.005951 -107.9
-0.0003357 0.005951 1 -95.12
comments: DE-IDENTIFIED (3008) [MR] AX T2 AC-PC line Entire Brain
study: e+1 MR HEAD WITHOUT CONTRAST
DOS: 02/06/2011 09:51:57
dw_scheme: 0,0,0,0

For the mrconvert command failing, this is because the series you’ve selected (0) corresponds to the T1, not the diffusion - there is no gradient information for these data. You need to select the second series (number 1)
The result as shown:

$ mrinfo 48310001/
mrinfo: [done] scanning DICOM folder “48310001/”
Select series (‘q’ to abort):
0 - 160 MR images 10:48:21 t1_mprage_sag_p2_iso (*tfl3d1_16ns) [11]
1 - 72 MR images 10:48:56 ep2d_diff_mddw_20_p2 (*ep_b0) [12]
2 - 25 MR images 10:53:02 ep2d_diff_mddw_20_p2_ADC (*ep_b0_1000) [13]
3 - 25 MR images 10:53:02 ep2d_diff_mddw_20_p2_TRACEW (*ep_b1000t) [14]
4 - 25 MR images 10:53:02 ep2d_diff_mddw_20_p2_FA (*ep_b0_1000) [15]
5 - 25 MR images 10:53:02 ep2d_diff_mddw_20_p2_ColFA (?) [16]
? 1
mrinfo: [100%] reading DICOM series “ep2d_diff_mddw_20_p2”
************************************************
Image: “Sun Cang (MR62192) [MR] ep2d_diff_mddw_20_p2”
************************************************
Dimensions: 128 x 128 x 25 x 72
Voxel size: 1.71875 x 1.71875 x 5.2 x ?
Data strides: [ -1 -2 3 4 ]
Format: DICOM
Data type: unsigned 16 bit integer (little endian)
Intensity scaling: offset = 0, multiplier = 1
Transform: 0.9996 4.488e-08 -0.02745 -107.9
-0.01197 0.8999 -0.4359 -82.52
0.0247 0.436 0.8996 -134.8
comments: Sun Cang (MR62192) [MR] ep2d_diff_mddw_20_p2
study: ZJ Hospital head
DOB: 27/01/1929
DOS: 19/10/2016 10:48:56
dw_scheme: [ 72 entries ]

$ mrview 48310001_mask.nii

Voxel size: 1.71875 x 1.71875 x 5.2 x ? There is a symbol “?” it seems strange, but it works well.

and I did fiber tracking with the number 30000. and when I viewed in MRview, it shows:

Cool! it works!

I feel sincere to thank you.
Chaoqing

OK, that would have answered it straight away: that dataset is a T2, not a diffusion MRI dataset…

Anyway, glad to hear you got all working in the end :+1:

Hi,Donald,

I have read some documents about T1,T2 and PD datasets. And I think T1-WI, T2-WI and PD-WI belong to DWI datasets, they are not DTI datasets. for there’s no gradient directions in DWI dataset, so we can not use the T1,T2 and PD datasets for fiber tracking. Am I right?

Thanks,
Chaoqing

Absolutely not… In your case, the relevant DICOM series is the one labelled ep2d_diff_mddw_20_p2. Looks like a Siemens-acquired dataset to me, and it basically means it’s a 2D multislice EPI sequence with diffusion preparation, acquired along 20 DW directions using the Diffusion product’s multi-direction DW mode, with parallel imaging factor 2. All the other series labelled with the same prefix (i.e. *_ADC, *_FA, etc). are scanner-generated derived data, which are essentially useless with MRtrix3 - but might be useful for on-scanner display.

The T1 can be used for tracking to help constraint the tractography - but it cannot replace the diffusion data in any way.