I tried to get the histogram for each segment with this code.
However, I got the same result for every segment.
I apologize for the inconvenience. Please check.
>>> labelValue = 1
Loading with imageIOName: GDCM
>>> labelmapVolumeNode =slicer.mrmlScene.AddNewNodeByClass("vtkMRMLLabelMapVolumeNode")
>>> segmentationNode = getNode('segmentation')
>>> volumeNode = getNode('Displacement Field')
>>> labelmapVolumeNode = getNode('LabelMapVolume')
>>> slicer.modules.segmentations.logic().ExportVisibleSegmentsToLabelmapNode(segmentationNode, labelmapVolumeNode, volumeNode)
True
>>> volumeArray = slicer.util.arrayFromVolume(volumeNode)
>>> labelArray = slicer.util.arrayFromVolume(labelmapVolumeNode)
>>> segmentVoxels = volumeArray[labelArray==labelValue]
>>> import numpy as np
>>> histogram = np.histogram(arrayFromVolume(volumeNode), bins=100)
>>> slicer.util.plot(histogram, xColumnIndex = 1)
(MRMLCorePython.vtkMRMLPlotChartNode)000002174751D408
>>> range = [-5.0, 5.0]
>>> bins = 100
>>> histogramR, histogramBins = np.histogram(arrayFromVolume(volumeNode)[:,:,:,0], bins, range)
>>> histogramA = np.histogram(arrayFromVolume(volumeNode)[:,:,:,1], bins, range)[0]
>>> histogramS = np.histogram(arrayFromVolume(volumeNode)[:,:,:,2], bins, range)[0]
>>> slicer.util.plot(np.vstack([histogramBins[:-1], histogramR, histogramA, histogramS]).T, xColumnIndex = 0, columnNames=['N', 'R', 'A', 'S'], title='Histogram')
(MRMLCorePython.vtkMRMLPlotChartNode)000002174751A3A8
>>> magnitudes = np.linalg.norm(arrayFromVolume(volumeNode), axis=3)
>>> histogram = np.histogram(magnitudes, bins=100)
>>> slicer.util.plot(histogram, xColumnIndex = 1, columnNames=['magnitude', 'N'], title="displacement")
(MRMLCorePython.vtkMRMLPlotChartNode)000002174751AE88
>>>