# Get histogram of vector volume

**URL:** <https://discourse.slicer.org/t/get-histogram-of-vector-volume/20473>\
**Category:** Development\
**Created:** [November 3, 2021, 2:19pm UTC](https://discourse.slicer.org/t/get-histogram-of-vector-volume/20473 "2021-11-03T14:19:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![toyama](https://avatars.discourse-cdn.com/v4/letter/t/82dd89/32.png) [@toyama](https://discourse.slicer.org/u/toyama)\
**Post date:** [November 3, 2021, 2:19pm UTC](https://discourse.slicer.org/t/get-histogram-of-vector-volume/20473/1 "2021-11-03T14:19:11Z")

</div>

I tried to get the histogram of the R, A, and S axes of the DVF of the contour thing by modifying the code that you taught me before.

> [@Negative Values in DVF Histogram](https://discourse.slicer.org/t/negative-values-in-dvf-histogram/19008):
>
> We are looking for a histogram of the DVF. The DVF should not have any negative values, but when I calculated the histogram from the DVF created by the transform module, it took negative values. What do these negative values mean? Also, I am converting a REG file created by MIMmaestro into a vector field by the transform module. Will this procedure create the same creation in 3DSlicer as the one created in MIMmaestro? I hope you can answer my question.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/b/5/b5b99a4efcd3cd1ba04d71a6fbc99dff32fe0a4e.png)

However, I wrote the following code, but an error occurred.  
I would like to know if there is any improvement.

> > > labelValue = 1  
> > > Loading with imageIOName: GDCM
> > > 
> > > labelmapVolumeNode =slicer.mrmlScene.AddNewNodeByClass(“vtkMRMLLabelMapVolumeNode”)  
> > > volumeNode = getNode(‘Displacement Field’)  
> > > labelmapVolumeNode = getNode(‘LabelMapVolume’)  
> > > segmentationNode = getNode(‘segmentation’)  
> > > segmentId = ‘box’  
> > > slicer.modules.segmentations.logic().ExportVisibleSegmentsToLabelmapNode(segmentationNode, labelmapVolumeNode, volumeNode)  
> > > True  
> > > volumeArray = slicer.util.arrayFromVolume(volumeNode)  
> > > labelArray = slicer.util.arrayFromVolume(labelmapVolumeNode)  
> > > import numpy as np  
> > > histogram = np.histogram(arrayFromVolume(volumeNode), bins=100)  
> > > histogramInSegment = histogram[arrayFromSegmentBinaryLabelmap(segmentationNode, segmentId) != 0]  
> > > Traceback (most recent call last):  
> > > File “”, line 1, in   
> > > TypeError: only integer scalar arrays can be converted to a scalar index

In addition, I have two questions.  
(1) What is the unit of the X-axis of DVF?  
Is it in mm or cm?  
(2) I would also like to know which axes A, S, and R in 3DSlicer represent respectively.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [November 4, 2021, 3:46am UTC](https://discourse.slicer.org/t/get-histogram-of-vector-volume/20473/2 "2021-11-04T03:46:18Z")

</div>

> [@toyama](#):
>
> histogramInSegment = histogram[arrayFromSegmentBinaryLabelmap(segmentationNode, segmentId) != 0]

There is a fundamental issue with this line. It seems that you want to filter parts of the histogram using spatial positions, which is impossible, because the histogram bins contain voxel count for the entire input array. You need to select the voxels that you are interested in before computing the histogram.

> [@toyama](#):
>
> What is the unit of the X-axis of DVF?

In DICOM and by default in Slicer, all length units are millimeter.

> [@toyama](#):
>
> I would also like to know which axes A, S, and R in 3DSlicer represent respectively.

Patient coordinate system directions, as defined in the DICOM standard (A = anterior = -posterior; S = superior; R = right = -left).
