I have segmented muscles on MRI scans every 10 slices and I would like to find the line of action of a muscle. I have to get the centroid of each area segmented to then draw a line between these points.

I can’t find a module to do that in Slicer.
Is there a module which calculate the centroid of each area segmented ? Or can we extract every outlines coordinates of each area segmented ?

If you want to get the centerline of the area segmented then you can use Extract Centerline module in VMTK extension. Once you have the centerline you can use Cross-section analysis module to get further information (cross-section areas, resliced images, etc.).

Unfortunatly, the Extract Centerline module don’t work on the muscle I’m intersting in. The centerline doesn’t follow the muscle line of action at all. I think it’s because this module is adapted to get the centerline of a vessel (which is thin and long) and not on a fat muscle.

If you share an example segmentation (upload the .seg.nrrd file somewhere and post the link here) then I can confirm.

Have you tried to use the SegmentGeometry extension? It can give you the coordinates of the centroid points along a reslice axis, which is exactly what you are looking for. The only possible inconvenience is that these centroid positions are reported in voxel coordinate system of the resampled volume, so if you need the centroid positions in RAS coordinate system then you’ll need to multiply voxel coordinates by IJKtoRAS matrix of the resampled volume.

Thank you very much. SegmentGeometry extension contains exactly what I was searching. Can you precise how I can transform voxel coordinates to RAS coodinates ?

Thank you but the IJKtoRAS matrix is a 3x3 matrix and I have only 2 coordinates in voxel (Cx, Cy). The multiplication between these 2 matrices is not possible. Can you help me with that ?

IJKtoRAS is a 4x4 homogenous matrix. As @mau_igna_06 said, if you have a single slice then K coordinate (third value) is 0. The last value is 1 if the coordinates specify a position (and 0 if the coordinates specify a direction vector). Note that this is not some Slicer specific thing but standard “homogeneous coordinates” representation and “homogeneous linear transformations”.

Thank you for your help.
I understand that I have to use the IJKtoRAS matrix to find the centroid coordinates in RAS coordinates system from IJK coordinates system.
I found a IJKtoRAS matrix in the “Segment” section. Can I use this matrix ?
I also found how to calculate the IJKtoRAS matrix with the origin and the spacing, but I don’t found the same result as the IJKtoRAS matrix in Slicer.
One last thing, the Slicer documentation says “Cx correspond to the resampled and cropped volume exported by SegmentGeometry”. Is that mean that the origin of IJK coordinates system is at then beginning of the segmented muscle and not at the beginning of the MRI image ?