Calculating centroid based on signal intensity

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

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.

1 Like

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!