# Extracting coordinates of muscle segmented on all slices from MRI scans

**URL:** <https://discourse.slicer.org/t/extracting-coordinates-of-muscle-segmented-on-all-slices-from-mri-scans/23441>\
**Category:** Support\
**Created:** [May 16, 2022, 1:45pm UTC](https://discourse.slicer.org/t/extracting-coordinates-of-muscle-segmented-on-all-slices-from-mri-scans/23441 "2022-05-16T13:45:36Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eva](https://avatars.discourse-cdn.com/v4/letter/e/dbc845/32.png) [@Eva](https://discourse.slicer.org/u/Eva)\
**Post date:** [May 16, 2022, 1:45pm UTC](https://discourse.slicer.org/t/extracting-coordinates-of-muscle-segmented-on-all-slices-from-mri-scans/23441/1 "2022-05-16T13:45:36Z")

</div>

Hello,

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 ?

Thank you for your response,

Eva

---

<div class="post-metadata">

**Author:** ![ebrahim](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ebrahim/32/13403_2.png) [@ebrahim](https://discourse.slicer.org/u/ebrahim)\
**Post date:** [May 16, 2022, 3:38pm UTC](https://discourse.slicer.org/t/extracting-coordinates-of-muscle-segmented-on-all-slices-from-mri-scans/23441/2 "2022-05-16T15:38:22Z")

</div>

Check out [segment statistics](https://slicer.readthedocs.io/en/latest/user_guide/modules/segmentstatistics.html)

---

<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:** [May 16, 2022, 9:46pm UTC](https://discourse.slicer.org/t/extracting-coordinates-of-muscle-segmented-on-all-slices-from-mri-scans/23441/3 "2022-05-16T21:46:18Z")

</div>

If you want to get the centerline of the area segmented then you can use `Extract Centerline` module in [VMTK extension](https://github.com/vmtk/SlicerExtension-VMTK/). Once you have the centerline you can use `Cross-section analysis` module to get further information (cross-section areas, resliced images, etc.).

You may also find [SegmentGeometry extension](https://github.com/jmhuie/Slicer-SegmentGeometry) useful.

---

<div class="post-metadata">

**Author:** ![Eva](https://avatars.discourse-cdn.com/v4/letter/e/dbc845/32.png) [@Eva](https://discourse.slicer.org/u/Eva)\
**Post date:** [May 17, 2022, 8:42am UTC](https://discourse.slicer.org/t/extracting-coordinates-of-muscle-segmented-on-all-slices-from-mri-scans/23441/4 "2022-05-17T08:42:14Z")

</div>

Thank you for your respond.

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.

Do you have an another solution ?

---

<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:** [May 28, 2022, 12:14am UTC](https://discourse.slicer.org/t/extracting-coordinates-of-muscle-segmented-on-all-slices-from-mri-scans/23441/5 "2022-05-28T00:14:50Z")

</div>

Centerline extraction with the “Tree” method should work even if the shape is not very elongated:

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

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](https://github.com/jmhuie/Slicer-SegmentGeometry)? 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.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/f/7/f7bd0cb50538a197fa8cf3387746d5b04a0a79cd.png)

@jmhuie

---

<div class="post-metadata">

**Author:** ![Eva](https://avatars.discourse-cdn.com/v4/letter/e/dbc845/32.png) [@Eva](https://discourse.slicer.org/u/Eva)\
**Post date:** [June 8, 2022, 7:44am UTC](https://discourse.slicer.org/t/extracting-coordinates-of-muscle-segmented-on-all-slices-from-mri-scans/23441/6 "2022-06-08T07:44:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mau\_igna\_06](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mau_igna_06/32/9056_2.png) [@mau\_igna\_06](https://discourse.slicer.org/u/mau_igna_06)\
**Post date:** [June 8, 2022, 9:57am UTC](https://discourse.slicer.org/t/extracting-coordinates-of-muscle-segmented-on-all-slices-from-mri-scans/23441/7 "2022-06-08T09:57:00Z")

</div>

Yuo need to use the ijkToRasTransformMatrix from the cirrent volume

---

<div class="post-metadata">

**Author:** ![Eva](https://avatars.discourse-cdn.com/v4/letter/e/dbc845/32.png) [@Eva](https://discourse.slicer.org/u/Eva)\
**Post date:** [June 8, 2022, 12:03pm UTC](https://discourse.slicer.org/t/extracting-coordinates-of-muscle-segmented-on-all-slices-from-mri-scans/23441/8 "2022-06-08T12:03:03Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![mau\_igna\_06](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mau_igna_06/32/9056_2.png) [@mau\_igna\_06](https://discourse.slicer.org/u/mau_igna_06)\
**Post date:** [June 8, 2022, 12:09pm UTC](https://discourse.slicer.org/t/extracting-coordinates-of-muscle-segmented-on-all-slices-from-mri-scans/23441/9 "2022-06-08T12:09:01Z")

</div>

If you have only two coordinates you should use something like appears on this post

> [@Center coordinates of volume slices?](https://discourse.slicer.org/t/center-coordinates-of-volume-slices/23133/8):
>
> Think I got it working (C++) by //---------------------------------------------------------------------- void GetBackgroundVolumeXYCenter(double slicePos[2]) { vtkMRMLSliceCompositeNode\* compositeNode = nullptr; compositeNode = vtkMRMLSliceCompositeNode::SafeDownCast(this-\>GetSliceNode()-\>GetScene()-\>GetFirstNodeByClass("vtkMRMLSliceCompositeNode")); const char\* backgroundVolumeID = compositeNode-\>GetBackgroundVolumeID(); double volumeBounds[6] = { 0.0 }; double volumeCente…

If you have 1 slice only you dhould add a 0 to the third coordinate

---

<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:** [June 13, 2022, 2:19pm UTC](https://discourse.slicer.org/t/extracting-coordinates-of-muscle-segmented-on-all-slices-from-mri-scans/23441/10 "2022-06-13T14:19:25Z")

</div>

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”.

---

<div class="post-metadata">

**Author:** ![Eva](https://avatars.discourse-cdn.com/v4/letter/e/dbc845/32.png) [@Eva](https://discourse.slicer.org/u/Eva)\
**Post date:** [June 27, 2022, 12:12pm UTC](https://discourse.slicer.org/t/extracting-coordinates-of-muscle-segmented-on-all-slices-from-mri-scans/23441/11 "2022-06-27T12:12:41Z")

</div>

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 ?
