Background: we are writing custom application with web UI for segmentation of 2D+time data. The semi-automatic algorithm relying on grow from seeds works well, but not all the time. So manual corrections are needed. Ideally, convert the label map into a 2D spline for each time point, to allow easy interaction. The structure of interest is smooth in these images, so smoothing of splines is a welcome side-effect. Converting that into a fractional label map is preferred over binary label map.
Segmentation module’s documentation mentions these conversions. It was already answered that direct editing of contours is not possible with Slicer. Is this still true? How hard would that be with an API, if one exists? Reuse is preferred over reimplementation.
Is conversion from binary label map into planar contours best done by converting to 3D mesh first, then cutting the mesh? Is that already implemented in Slicer, and where?
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 does not contain a lot of code.
The last question about this 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?
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:
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).
I agree that current markups curves should be able to handle editing quite well.
We just need an algorithm for getting closed curves from segmentation/slice intersections. It would require two steps:
segmentation slicing (cut segmentation with slice): The implementation in the segmentation 2D displayable manager and in the exporter (that @cpinter linked above) are about the same and should be usable for simple shapes. For complex cases you would need to use vtkContourTriangulator class but we could not switch to it because it has a small but serious bug that may cause the application hang for invalid inputs (see details here: https://github.com/Slicer/SlicerGitSVNArchive/pull/1075).
spline fitting: we could create a spline by resampling the linearly interpolated contour at uniform distances and use these as control points