Calculate external contour for segment in segmentation

I’m trying to calculate external contour and then transform it into markups curve node.Here is a VTK example with such case. Position and orientation of camera are known. Segment polydata is white, background is black.

Can the same VTK filter be used in 3D Slicer, or the program has builtin methods for that?

Code below gives an empty polydata:

    view =
    renderWindow = view.renderWindow()
    renderers = renderWindow.GetRenderers()
    renderer = renderers.GetItemAsObject(0)

    winToImageFilter = vtk.vtkWindowToImageFilter()
    winToImageFilter.SetScale(2) #image quality

    contFilter = vtk.vtkContourFilter()
    contFilter.SetValue(0, 255)

    # Make the contour coincide with the data.
    contour = contFilter.GetOutput()

Data example

I’m not aware of any function ready-made in Slicer for this. I think your approach is reasonable. On thought is that maybe you want to switch to orthogonal projection instead of the default perspective for this. Or maybe not, if you want the contour that is visible from a point in space.

I think you could apply a projection transform to your model using your camera. And you may need to use vtkFeatureEdges after that in some combination of options

This may be related:

Hope it helps

Thank both of you!
I will try several approaches and let you know. I’ve found some mistakes in my script and now trying to fix them.

The VTK example works but orientation and scale of the contour model must be modified.