# ImageMomentsCalculator how to in python

**URL:** <https://discourse.itk.org/t/imagemomentscalculator-how-to-in-python/2402>\
**Category:** Algorithms\
**Tags:** simpleitk, python\
**Created:** [November 13, 2019, 10:44pm UTC](https://discourse.itk.org/t/imagemomentscalculator-how-to-in-python/2402 "2019-11-13T22:44:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kayarre](https://discourse.itk.org/user_avatar/discourse.itk.org/kayarre/32/669_2.png) [@kayarre](https://discourse.itk.org/u/kayarre)\
**Post date:** [November 13, 2019, 10:44pm UTC](https://discourse.itk.org/t/imagemomentscalculator-how-to-in-python/2402/1 "2019-11-13T22:44:51Z")

</div>

I want to use the imageMomentsCalculator to get the “center of mass” of an image how could one do this with the python interface?

it appears its only indirectly available as part registration intialization?

---

<div class="post-metadata">

**Author:** ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)\
**Post date:** [November 14, 2019, 4:16am UTC](https://discourse.itk.org/t/imagemomentscalculator-how-to-in-python/2402/2 "2019-11-14T04:16:56Z")

</div>

Hi @kayarre,

Center of gravity can be calculated with:

```auto
moments = itk.ImageMomentsCalculator.New(image)
moments.Compute()
center_of_gravity = moments.GetCenterOfGravity()

```

Hope this helps,  
Matt
