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.
image
The label map for the volume was created with ā€œlabelValue = 1ā€.
image
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.
image
image

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.
image
image
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?
image
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.
image

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.
image
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 = slicer.app.layoutManager()
renderWindow = layoutManager.plotWidget(plotWidgetIndex).plotView().renderWindow()
exp = vtk.vtkGL2PSExporter()
exp.SetRenderWindow(renderWindow)
exp.CompressOff()
exp.SetFileFormatToSVG()
exp.SetFilePrefix(filename[:-4]) # file prefix expects filename without extension
exp.Write()

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