# Convert segmentation to closed curve markup

**URL:** <https://discourse.slicer.org/t/convert-segmentation-to-closed-curve-markup/27182>\
**Category:** Support\
**Created:** [January 10, 2023, 11:22pm UTC](https://discourse.slicer.org/t/convert-segmentation-to-closed-curve-markup/27182 "2023-01-10T23:22:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![MayaSF](https://avatars.discourse-cdn.com/v4/letter/m/bc79bd/32.png) [@MayaSF](https://discourse.slicer.org/u/MayaSF)\
**Post date:** [January 10, 2023, 11:22pm UTC](https://discourse.slicer.org/t/convert-segmentation-to-closed-curve-markup/27182/1 "2023-01-10T23:22:31Z")

</div>

Hi there,  
Is there a way I can convert a Segmentation to a Closed Curve Markup by sampling the outside boundary of the segmented area with a certain number of points? I find it significantly faster to use the Draw tool in Segment Editor to outline my specimens than to place hundreds of points with the Closed Curve Markup tool. However, I would like to export my outlines as json files rather than nrrd files, so they are easier to work with in R. Appreciate any suggestions you have.

Best,  
Maya

---

<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:** [January 11, 2023, 4:52am UTC](https://discourse.slicer.org/t/convert-segmentation-to-closed-curve-markup/27182/2 "2023-01-11T04:52:01Z")

</div>

Do you work with 3D data or just a single 2D image?

For 3D data, planar contour representation is highly problematic - based on our experience with RTSTRUCT DICOM information objects).

What is your end goal? What kind of processing or analysis would you like to do?

---

<div class="post-metadata">

**Author:** ![MayaSF](https://avatars.discourse-cdn.com/v4/letter/m/bc79bd/32.png) [@MayaSF](https://discourse.slicer.org/u/MayaSF)\
**Post date:** [January 11, 2023, 5:39pm UTC](https://discourse.slicer.org/t/convert-segmentation-to-closed-curve-markup/27182/3 "2023-01-11T17:39:58Z")

</div>

Hi Andras,  
Thanks for your reply! In this case, I am working with 2D images. My end goal is to make a number of measurements based on each outline, and I already have an R script that makes all these measurements and runs model comparison from coordinates in json files (I am not as comfortable in python). I do not think I can export a segmentation in a file format compatible with my R script, so converting the segmentations to closed curve markups would be the quickest solution to finish the pipeline.

---

<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:** [January 11, 2023, 6:02pm UTC](https://discourse.slicer.org/t/convert-segmentation-to-closed-curve-markup/27182/4 "2023-01-11T18:02:53Z")

</div>

I see, it makes sense then. Some 2D measurements (such as perimeter) are indeed the easiest is to compute from a polyline representation.

To get a polyline representation from a labelmap image representation, you can use vtkDiscreteFlyingEdges2D followed by a vtkContourTriangulator. You can use VTK either in Python (in Slicer) or in R.

---

<div class="post-metadata">

**Author:** ![MayaSF](https://avatars.discourse-cdn.com/v4/letter/m/bc79bd/32.png) [@MayaSF](https://discourse.slicer.org/u/MayaSF)\
**Post date:** [January 11, 2023, 6:05pm UTC](https://discourse.slicer.org/t/convert-segmentation-to-closed-curve-markup/27182/5 "2023-01-11T18:05:23Z")

</div>

Perfect, thanks again!
