I have a set of patients’ dti images. How do I extract the 3x3 diffusion tensor matrices per each voxel? Additionally how do I convert the DTI image to nrrd format, can I still use the DWIconvert module even though its not a DWI image?
Hi,
Thanks for the response, how do these methods to get the diffusion tensors translate to the slice depth. Per patient I have around 26 images, will the methods give me the tensors for a specified slice depth or for all of them? Additionally, when you run the code given in the links in the interactive python window, where does the information containing the diffusion tensors go? What format is it saved in?
You can get all the tensors. The mapping between slices, rows, and columns (IJK) and tensor samples is by the 3D array where each element is a 3x3 tensor. The mapping to patient space is defined by the IJKToRAS transform (and any other applied transforms). The tensors themselves are measured with respect to the Measurement Frame, a 3x3 matrix you can get from the node.
The values are stored in python variables so you can use them to perform further calculations or save them out to a file if you want.
You’re very welcome. Feel free to ask follow ups if needed.
Hi,
So if they save as variables in python would I be able to access them through a jupyter notebook after they saved? How would I save them out as a file (sorry I’m new to this). Additionally, in the links you posted contain nested forloops, how does this work in the python window (since isnt the window just a line by line execution?)
Additionally, if I create a brain mask of each image and then extract the tensors, will this prevent me from getting the skull tensor data (which I dont need).
How can I create brain masks of all my patients and save them to the program so that whenever I come back to continue work I only work on the updated imaged? Is there a simple way I can save this, for example the format given in the DCM window that separates the data per patient and series?
Again, thank you for the response!
The tutorials helped a lot, but I still couldnt figure out how to save the diffusion tensors as a file. Specifically, I am trying to export all the diffusion tensors to matlab and work with them there. Is there a way to do this?
Thank you again for the replies. I am trying to use matlab to compare to another analysis done in that software. I have been trying save the image data however I keep getting this error. What am I doing wrong? Additionally, if I wanted to save as a .mat file how would i do so since scipy isnt built into slicer? Please let, I am really just trying to extract this data so I can work with it easier in Matlab.
Hi! I’m not sure what your goal is in the code? The code loops through the tensors but doesn’t do anything with the data. The last error is because the save function expects a node, but the code gives it an image data.
Hi Andras,
How can I iterate or see values inside the tensor variable which is a vtkfloatarray. is there a way to convert to numpy and then iterate over the array.
Hi,
I need to get the tensor values from DTI image. I got the values using the following code but all the values are same. I think the values should be different for each voxel. Could you please tell me if there is something wrong with the following code:
tensors = slicer.util.array(inputVolume.GetID())
volumeNode=slicer.util.getNode(inputVolume.GetID())
imageData=volumeNode.GetImageData()
tensors = imageData.GetPointData().GetTensors()
extent = imageData.GetExtent()
idx = 0
for k in range(extent[4], extent[5]+1):
for j in range(extent[2], extent[3]+1):
for i in range(extent[0], extent[1]+1):
tensors.GetTuple9(idx)
idx += 1
import json
f = open('/home/saima/Downloads/Damon/Damon/Case131/tensors.txt', 'w')
for x in range(5300):
print(tensors.GetTuple(x))
f.write(json.dumps(tensors.GetTuple(x)))