Diffusion tensor exportation to matlab

Hello every one,

I’m using 3D Slicer 4.10.1. I’m trying to export the FA-colored map to MatLab, generated by following the DTI tutotrial and using the Human Connectome Project data. Therefore, I want to export diffusion tensor data for each voxel to MatLab. However, I tried the code “Python code to access tensor data from a DTI volume” (https://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/ScriptRepository#Access_values_in_a_DTI_tensor_volume)" but I couldn’t export… Does someone know what happen? and why can"t I export the data ?

Regards

Hi what is your goal?

By accessing each voxel in Python you could write code to export the data.

Or you could not use python. Just save as nrrd and use a Matlab nrrd reader.

However, the DTI is not the same as the FA color image or DEC map. If you want to see this in Matlab you would need to write code to generate it from the DTI.

So please clarify your eventual goal so we can best advise.

Hi @ljod,

I’m currently using an nrrd-nhdr reader toolbox in MatLab. However, I can read the geometry but not the FA colored map from with the DWI (.nrrd) and DTI (.nhdr) files.

The first objective is to average the diffusion information (FA and vector of anisotropy) with elements with a larger size than the voxels as described below. Hence, the final objective is to build an anisotropic finite element human head model as Giordano et al. did (The influence of anisotropy on brain injury prediction)

Capture2
Capture

Hi thanks. There is no such thing as vector of anisotropy. I think you mean the eigenvector corresponding to the largest eigenvalue. Then the other thing you want to export is just the computed FA image, which should be straightforward as a nrrd image. You do not want to export the RGB color image, which will lack all information you need.

If you want Slicer to compute the eigenvector for you, you should look in the code for where the tensor glyphs are displayed. This can be used in the volumes module GUI where the options are for displaying tensors. Look at the tensors as glyphs, sticks specifically, aligned with major eigenvector. You can write similar code in python to get the eigenvectors and use the correct vector for export. Probably easiest to export this information as three nrrrd images, one for each component.

You’ll need to carefully check coordinate systems and view these vectors in Matlab to make sure the major eigenvectors are correctly aligned with the anatomy. I recommend viewing as glyphs in slicer and comparing.

Thank you very much for your help !!! I got stuck for a while… I’ll do that !!

Just out of curiosity, why do you plan to use Matlab?

Have you considered using Python? It would have many advantages.

Hi @lassoan,

I use MatLab because I’ll need it later for the writing a script for LS-Dyna (a solver for finite element method) which links the mechanical properties with the directions of anisotropy

There should be freely available Python packages for LS-Dyna file reading/writing. For example, you may check out this one: http://www.qd-eng.de/index.php/2018/02/19/manipulating-ls-dyna-keyfiles-in-python/.

I didn’t even know that it was possible… Thanky you for the information !