# Convert binary label map into 2D contours (ideally splines) and back

**URL:** <https://discourse.slicer.org/t/convert-binary-label-map-into-2d-contours-ideally-splines-and-back/11135>\
**Category:** Development\
**Created:** [April 15, 2020, 10:54pm UTC](https://discourse.slicer.org/t/convert-binary-label-map-into-2d-contours-ideally-splines-and-back/11135 "2020-04-15T22:54:03Z")\
**Posts on this page:** 1\
**Showing post:** 4

<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:** [April 16, 2020, 8:31am UTC](https://discourse.slicer.org/t/convert-binary-label-map-into-2d-contours-ideally-splines-and-back/11135/4 "2020-04-16T08:31:50Z")

</div>

> [@jcfr](#):
>
> Is that already implemented in Slicer, and where?

Storing and managing segmentation data in a series of 2D contours is a legacy method, and so far we only needed it for DICOM-RT Structure Set, and did not want to encourage its use (especially that there is the DICOM Segmentation Object, which is much superior to RTSS). This is why we did not even implement a conversion rule going from labelmap to planar contour, but the code that does the conversion is in the exporter function itself:

> <https://github.com/SlicerRt/SlicerRT/blob/master/DicomRtImportExport/Logic/vtkSlicerDicomRtImportExportModuleLogic.cxx#L2451-L2499>

If you want it could be outsourced though. Any thoughts @lassoan @Sunderlandkyl?

> [@jcfr](#):
>
> Is there an easy or already implemented way of converting the resulting 2D polygon into a spline? Pointers into relevant code are appreciated, as [vtkLinearSpline.cxx](https://github.com/Slicer/Slicer/blob/master/Modules/Loadable/Markups/MRML/vtkLinearSpline.cxx) does not contain a lot of code.
> 
> The last [question about this](https://discourse.slicer.org/t/planar-contours-and-binary-label-maps/3778) was two years ago. Did anything important change? Can someone point me to relevant pieces of code for ripping it out of Slicer and into a stand-alone executable?

With the recent addition of the new Markup type of closed curve this would be much easier to do than before. The only thing we’d need is a converter from/to planar contour segmentations (and the abovementioned labelmap → contours conversion, since the other way is implemented already).

---

_[View the full topic](https://discourse.slicer.org/t/convert-binary-label-map-into-2d-contours-ideally-splines-and-back/11135)._
