ADC histogram of segmented brain lesion

Good evening! Could you suggest me the easiest way to calculate the ADC histogram of a segmented brain lesion? I am able to segment a lesion and have its volume but still I don’t find the way to have ADC values.
Thanks

I believe you will need to do a little scripting for that. Mask the ADC volume with the segmentation and then make a histogram like this:

https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html

Is it necessary to do it with Python? or there is an easiest workflow?
Is it possible to find some screenshots or a tutorial?
thanks

You can use the Mask Volume effect in Segment Editor to create a volume that only contain the voxels in the segmented region and you can see its histogram in Volumes module. but it will require about 10 clicks and all you get is a visual representation of the histogram.

Since in most cases you need to further process the histogram (e.g., compute a percentile) and might also want to analyze data in batch mode (instead of manually clicking through the GUI), it is usually more convenient to copy-paste a few lines of Python script into the Python console. You don’t need any Python scripting experience, just to be able to copy and paste code the code below into the Python console (hit Ctrl + 3 to show the console).

# Get input data (use the first volume, segmentation, and segment that are found in the scene)
volumeNode = slicer.mrmlScene.GetFirstNodeByClass("vtkMRMLScalarVolumeNode")
segmentationNode = slicer.mrmlScene.GetFirstNodeByClass("vtkMRMLSegmentationNode")
segmentId = segmentationNode.GetSegmentation().GetNthSegmentID(0)

# Get voxel values of the volume in the segmented region
import numpy as np
volumeArray = slicer.util.arrayFromVolume(volumeNode)
segmentArray = slicer.util.arrayFromSegmentBinaryLabelmap(segmentationNode, segmentId, volumeNode)
segmentVoxels = volumeArray[segmentArray != 0]

# Compute and plot histogram
import numpy as np
histogram = np.histogram(segmentVoxels, bins=50)
slicer.util.plot(histogram, xColumnIndex = 1)

(adapted from this code snippet in the script repository)

Thank you very muche for the answer. Unfortunatelly I find an error I can’t solve during the procedure, it’s like we give 3 arguments instead of 2?

volumeNode = slicer.mrmlScene.GetFirstNodeByClass(“vtkMRMLScalarVolumeNode”)

volumeNode = slicer.mrmlScene.GetFirstNodeByClass(“vtkMRMLScalarVolumeNode”)

segmentationNode = slicer.mrmlScene.GetFirstNodeByClass(“vtkMRMLSegmentationNode”)
segmentId = segmentationNode.GetSegmentation().GetNthSegmentID(0)
import numpy as np
volumeArray = slicer.util.arrayFromVolume(volumeNode)
segmentArray = slicer.util.arrayFromSegmentBinaryLabelmap(segmentationNode, segmentId, volumeNode)
Traceback (most recent call last):
File “”, line 1, in
TypeError: arrayFromSegmentBinaryLabelmap() takes 2 positional arguments but 3 were given

Hello,
I’m running into a similar error when pasting the above mentioned code into the python interactor.
What I would like to do is to obtain a histogram from a segmented area from a T2 relaxometry map. So I figured I could use the code in a comparable way. I use Slicer 4.11.0 on Windows 10 Pro.
Any help with this is highly appreciated, unfortunately I’m not very strong in coding…
Thank you a lot!
Please find a screenshot from my scene with the error message attached.

You need to use a recent Slicer Preview Release (Slicer-4.13).

Thanks a lot, it worked!

1 Like

Thank you! now it works!
Is it possible to download the entire dataset of the histogram to export them in excel?

Thanks a lot

The histogram is already in a table that is saved as a .csv or .tsv file.

You can hit Ctrl-S to save all nodes, including the table. Or you can go to Data module and right-click on the table node and choose Export to file....

Great! it works!
thank you very much

1 Like