# Center of mass calculation

**URL:** <https://discourse.slicer.org/t/center-of-mass-calculation/38243>\
**Category:** Support\
**Tags:** dicom\
**Created:** [September 5, 2024, 5:38pm UTC](https://discourse.slicer.org/t/center-of-mass-calculation/38243 "2024-09-05T17:38:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![francois](https://avatars.discourse-cdn.com/v4/letter/f/77aa72/32.png) [@francois](https://discourse.slicer.org/u/francois)\
**Post date:** [September 5, 2024, 5:38pm UTC](https://discourse.slicer.org/t/center-of-mass-calculation/38243/1 "2024-09-05T17:38:35Z")

</div>

How can we ignore part a volume in order to calculate a center of mass, based on HU. It seems that each tine it takes into account the “empty” voxels whatever value is applied: 0 or NaN.

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [September 6, 2024, 9:03am UTC](https://discourse.slicer.org/t/center-of-mass-calculation/38243/2 "2024-09-06T09:03:12Z")

</div>

You need to segment your region of interest with Segment Editor, then from there it’s very easy to get the center of mass of the segment using Segment Statistics for example.

---

<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:** [September 6, 2024, 10:48am UTC](https://discourse.slicer.org/t/center-of-mass-calculation/38243/3 "2024-09-06T10:48:41Z")

</div>

@francois You can ignore part of a volume that is outside a segment as @cpinter described. You can also get a point inside a segment nearest to its center using [segmentationNode.GetSegmentCenterRAS](https://discourse.slicer.org/t/get-center-of-gravity-of-a-segment/4287/4) (this is useful if you want to jump to a slice where the segment is visible; the center of gravity may be outside the segment). If to7 want to compute the center of gravity yourself then you can do so using numpy (you can use `np.where` to ignore values that are outside the range you are interested in).

Note that 0 HU value corresponds to water (fat, soft tissue, …) so it might not be suitable as a threshold. HU value of air is -1000, you can use that as a thrshold for determining if a voxel is “empty”.

What would you like to use center of gravity for?

---

<div class="post-metadata">

**Author:** ![francois](https://avatars.discourse-cdn.com/v4/letter/f/77aa72/32.png) [@francois](https://discourse.slicer.org/u/francois)\
**Post date:** [September 6, 2024, 11:16am UTC](https://discourse.slicer.org/t/center-of-mass-calculation/38243/4 "2024-09-06T11:16:25Z")

</div>

Well I work on bone (foot bones) using WBCT dicoms. I want to transform both the dicom volume and the segment to a new reference frame where the COM is the origin.

---

<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:** [September 6, 2024, 1:37pm UTC](https://discourse.slicer.org/t/center-of-mass-calculation/38243/5 "2024-09-06T13:37:52Z")

</div>

In this case, center of gravity computed based on HU might not what you need (you don’t want cortical bone to throw off computation of the bone axis), but you may want to use solidified segmentation of the bone.

Check out this extension - it may provide useful features for you:

> **[GitHub - jmhuie/SlicerBiomech: Extension for the collection and analysis of...](https://github.com/jmhuie/SlicerBiomech)**
>
> Extension for the collection and analysis of biomechanical data from 3D specimen data

You can get fully automatic human feet bones segmentation from TotalSegmentator extension.

---

<div class="post-metadata">

**Author:** ![ChristopherGray](https://avatars.discourse-cdn.com/v4/letter/c/ed8c4c/32.png) [@ChristopherGray](https://discourse.slicer.org/u/ChristopherGray)\
**Post date:** [September 18, 2024, 1:42pm UTC](https://discourse.slicer.org/t/center-of-mass-calculation/38243/6 "2024-09-18T13:42:08Z")

</div>

Thank you so much for the extension link.
