# Centroid Voxel/Coordinates Intensity Value Measurement - Is it possible?

**URL:** <https://discourse.slicer.org/t/centroid-voxel-coordinates-intensity-value-measurement-is-it-possible/25218>\
**Category:** Support\
**Tags:** quantitative, coordinates, markups-fiducials\
**Created:** [September 12, 2022, 1:29pm UTC](https://discourse.slicer.org/t/centroid-voxel-coordinates-intensity-value-measurement-is-it-possible/25218 "2022-09-12T13:29:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dokay1](https://avatars.discourse-cdn.com/v4/letter/d/b4bc9f/32.png) [@dokay1](https://discourse.slicer.org/u/dokay1)\
**Post date:** [September 12, 2022, 1:29pm UTC](https://discourse.slicer.org/t/centroid-voxel-coordinates-intensity-value-measurement-is-it-possible/25218/1 "2022-09-12T13:29:20Z")

</div>

I bumped into an issue I can’t seem to find a solution for. I have a large number (\>400) of segments for each I want to measure the intensity (essentially the anatomical location off an atlas) from the centroid voxel. I used Segment Statistics to export the Centroid coordinates and I can import those into a fiducial list.

I’m wondering what would be the best way to get the intensity data from the centroids?  
A) I could import the coordinates into a fiducial list, but is there a way to get values from the fiducial’s coordinates?  
B) Can I shrink the segments to a single central voxel? (this would be the simplest)  
C) DO i have to generate 400+ transforms with the coordinates and use a single central voxel to get the data?

Please help!

---

<div class="post-metadata">

**Author:** ![dokay1](https://avatars.discourse-cdn.com/v4/letter/d/b4bc9f/32.png) [@dokay1](https://discourse.slicer.org/u/dokay1)\
**Post date:** [September 28, 2022, 2:43pm UTC](https://discourse.slicer.org/t/centroid-voxel-coordinates-intensity-value-measurement-is-it-possible/25218/2 "2022-09-28T14:43:26Z")

</div>

Solution:

1. I used LabelmapSegmentStatistics to pull the centroid for each segment in the Segmentation
2. Then I used the centroid coordinates to generate new spherical segments with a 1mm diameter (or radius?)
3. These can be used with Segment statistics to query core lesion locations based on anatomical atlases

```auto
# Pull Centroids and generate 1mm spheric lesions in centroid for anatomical assessment 
# Adjust name for "Segmentation" and "Volume" as needed

import numpy as np
import SegmentStatistics
segmentationNode = slicer.util.getNode("Segmentation")
volume_node = slicer.util.getNode("Volume")
segmentation = segmentationNode.GetSegmentation()
segnum = segmentation.GetNumberOfSegments()
for i in range(segnum):
    segment = segmentation.GetNthSegment(i) 
    segmentId = segmentationNode.GetSegmentation().GetSegmentIdBySegment(segment)
    segmentName = segment.GetName()
    segStatLogic = SegmentStatistics.SegmentStatisticsLogic()
    segStatLogic.getParameterNode().SetParameter("Segmentation", segmentationNode.GetID())
    segStatLogic.getParameterNode().SetParameter("LabelmapSegmentStatisticsPlugin.centroid_ras.enabled", str(True))
    segStatLogic.computeStatistics()
    stats = segStatLogic.getStatistics()
    print(segmentName)
    centroid_ras = stats[segmentId,"LabelmapSegmentStatisticsPlugin.centroid_ras"]
    print(centroid_ras)
    tumorCentroid = vtk.vtkSphereSource()
    tumorCentroid.SetCenter(centroid_ras)
    tumorCentroid.SetRadius(1)
    tumorCentroid.Update()
    CentroidSegmentName = segmentName + "-centroid"
    segmentId = segmentationNode.AddSegmentFromClosedSurfaceRepresentation(tumorCentroid.GetOutput(), CentroidSegmentName, [1.0,0.0,0.0])

```
