Getting Voxel Values

We would like to get the values of all the voxels in a segment.
However, the segment statics only gives me the maximum and minimum values for each contour.
Is there any way to get the values of the voxels statistically?

Whenever I use segment statistics it gives the mean, median, standard deviation etc. Have you tried scrolling across to see the whole table? You could ensure all the options are ticked under the “Advanced” drop down menu also?

1 Like

You can get all voxels of the segment and compute statistics as in this example.

Thank you for your answer.
I started with “# Compute histogram” in “Get histogram of a segmented region” based on the series and segments I had loaded beforehand.
The label map for the volume was created with “labelValue = 1”.
However, when I proceeded to the next “# Get segmentation as labelmap volume node”, I got an error message. changing the name of the segment to segmentation as in the Script repository example did not help.

You need to set the segmentationNode variable. For example, if the name of your segmentation node is Segmentation then you can set the variable by calling:

segmentationNode = getNode('Segmentation')

Thank you for your answer.
I was able to get a histogram by specifying segmentationNode, labelmapVolumeNode, and masterVolumeNode.
When I change the plot type of the histogram from “scatter plot”, the value of the X axis changes, why is this? Looking at the table, scatter seems to be correct.
Also, when I try to save the plot chart as an svg file, I get a “file not found” message. Is there any other way to save it?
I apologize for the inconvenience, but I would appreciate your response.

Let me ask you an additional question.
It worked once, but when I entered the same code.
I get an error like the one in the image.
I think labelArray = slicer.util.arrayFromVolume(labelmapVolumeNode) is not invoked properly, is there any reason for this?
Sorry I am not familiar with python.

It’s cut off in your screenshot but it appears you left off the () and arguments at the end of ExportVisibleSegmentsToLabelmapNode so it’s never invoked and the labelmapVolumeNode is never populated.

Thank you very much for your answer.
I managed to fix the error with this code.
Thank you very much.

Scatter plot uses a specified table column as x axis values. Line plot uses point index (0, 1, 2, …) as x axis values.

Good catch, there was a small bug in how the filename was assembled and indeed saving failed. This will be fixed in tomorrow’s Slicer Preview Release.

Until then you can use this code snippet as a workaround:

filename = "c:/tmp/test.svg"
plotWidgetIndex = 0
layoutManager =
renderWindow = layoutManager.plotWidget(plotWidgetIndex).plotView().renderWindow()
exp = vtk.vtkGL2PSExporter()
exp.SetFilePrefix(filename[:-4]) # file prefix expects filename without extension

Thank you for your answer.
I have downloaded the latest version for July 7, 2021.
However, when I tried to install RegistrationQA in this version, it was not in the extensions.
Is RegistrationQA no longer covered in the latest version?
If the latest version does not have RegistrationQA, I will use the code you gave me for the previous version.

I’ve fixed an error that made the extension fail to build. Download the latest Slicer Preview Release tomorrow and let me know if the extension is still not available.

2 posts were split to a new topic: Get voxel values as a CSV file