# Calculating centroid based on signal intensity

**URL:** <https://discourse.slicer.org/t/calculating-centroid-based-on-signal-intensity/32956>\
**Category:** Support\
**Tags:** segmentation\
**Created:** [November 22, 2023, 12:31pm UTC](https://discourse.slicer.org/t/calculating-centroid-based-on-signal-intensity/32956 "2023-11-22T12:31:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ingunnev](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ingunnev/32/68406_2.png) [@ingunnev](https://discourse.slicer.org/u/ingunnev)\
**Post date:** [November 22, 2023, 12:31pm UTC](https://discourse.slicer.org/t/calculating-centroid-based-on-signal-intensity/32956/1 "2023-11-22T12:31:16Z")

</div>

Hello!

I am working on a project where calculating the centroid of a segmentation based on the intensity in each voxel in the MRI-picture could be interesting. Slicer had a centroid calculation option easily available, but it only told me the geometrical centroid of a segmentation, not a centroid based on intensity.

I have tried (with some assistance from friends) to use the python console to extract the data (both the intensity voxels from the MRI-image, and the position of the segmentation). It didn’t seem very straightforward, so if anybody could give some guidance it would be very helpful!

I also looked for solutions online, but I couldn’t find anything that helps, or anybody with the same issue.

Best regards,  
Ingunn

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [November 22, 2023, 5:36pm UTC](https://discourse.slicer.org/t/calculating-centroid-based-on-signal-intensity/32956/2 "2023-11-22T17:36:39Z")

</div>

This is a good question and thanks for asking it. I don’t think we have an example just like that in our script repository, so rather than writing out a long description myself I tried an experiment by pasting into google’s bard tool. The answer below is probably not exactly correct, but from a quick read it looks close. Other tools like ChatGPT or microsoft bing would also probably do a good job and maybe if you try and then ask follow up questions you will be able to debug it.

> **[‎In 3D Slicer: Hello!

I am working on a project where calculating the...](https://bard.google.com/share/fa6b4851c529)**
>
> Created with Bard.

---

<div class="post-metadata">

**Author:** ![ingunnev](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ingunnev/32/68406_2.png) [@ingunnev](https://discourse.slicer.org/u/ingunnev)\
**Post date:** [November 23, 2023, 10:43am UTC](https://discourse.slicer.org/t/calculating-centroid-based-on-signal-intensity/32956/3 "2023-11-23T10:43:07Z")

</div>

Thank you for your answer!  
I actually asked ChatGTP 3.5, but the answer seemed to lack some necessary parts for the script to work. The answer from Bard seems more extensive.  
I will give it a try!
