# Closed curves - centroid and eplipse long and short axis

**URL:** <https://discourse.slicer.org/t/closed-curves-centroid-and-eplipse-long-and-short-axis/26761>\
**Category:** Support\
**Created:** [December 16, 2022, 8:53am UTC](https://discourse.slicer.org/t/closed-curves-centroid-and-eplipse-long-and-short-axis/26761 "2022-12-16T08:53:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Igor\_S](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/igor_s/32/14237_2.png) [@Igor\_S](https://discourse.slicer.org/u/Igor_S)\
**Post date:** [December 16, 2022, 8:53am UTC](https://discourse.slicer.org/t/closed-curves-centroid-and-eplipse-long-and-short-axis/26761/1 "2022-12-16T08:53:52Z")

</div>

Hello,

I’ve drawn a closed curve on DICOM image. How do you calculate centroid of closed curve?  
Can you approximate ellipse from closed curve and calculate longest and short axis of this ellipse?  
I would like to implement this steps in a script, but haven’t found anything similar in script repository (there is and example of segment statistics, but I draw my closed curve on raw DICOM not on segmented images).

Thank you fro your help!

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [December 16, 2022, 4:07pm UTC](https://discourse.slicer.org/t/closed-curves-centroid-and-eplipse-long-and-short-axis/26761/2 "2022-12-16T16:07:14Z")

</div>

You can use something like `slicer.util.arrayFromMarkupsCurvePoints(slicer.util.getNode("CC"))` where “CC” is the default name of the closed curve. With that array you can do whatever fitting and calculations you need. Along with the examples in [the script repository](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#markups) you should have what you need.

---

<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:** [December 16, 2022, 8:27pm UTC](https://discourse.slicer.org/t/closed-curves-centroid-and-eplipse-long-and-short-axis/26761/3 "2022-12-16T20:27:32Z")

</div>

To fit an ellipse to the curve, you can slightly modify the [sphere fitting example](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#specify-a-sphere-by-multiple-control-points) in the script repository. Or, you can project all your curve points to a best-fit plane and then do a [2D ellipse fitting](https://scipython.com/blog/direct-linear-least-squares-fitting-of-an-ellipse/).
