"How to render the pixel contour of an image" Follow-Up

I have a follow-up question to this thread: https://public.kitware.com/pipermail/vtkusers/2011-June/068268.html

I have the same problem that his example pictures demonstrate well - I want to render the edges of the “inside” mask pixels, not contours that pass halfway through pixels.

The response “To see the contours of my voxel based segmentation fields I threshold
the binary dataset and extract its edges” makes sense to me, but does somebody have more detailed instructions on how to accomplish this?

Thank you,

We have a simple VTK filter for this in 3D Slicer that you could use:

Labelmap image overlaid as is:

Labelmap image overlaid with vtkImageLabelOutline filter applied:

However, in the past couple of years we’ve learned that showing just the contour is insufficient (it is often not clear what is inside and what is outside), while showing only a filled overlay often decreases the contrast of underlying structures too much. So, most of the time you want to show both: a strong outline and a highly transparent filling.

Since recent VTK performance improvements, it is also possible to generate 3D models extremely quickly and use that to generate slice outlines and filling. This allows contour smoothing and synchronization of 2D and 3D representations:

Filling is not trivial in this case - you either go for high speed and sometimes inverted inside/outside contours or very slow but reliable vtkContourTriangulator.

You can find the VTK pipeline of all these visualization modes here. You can take the code and use it in your own software, but if you work with medical images then it may make more sense to create a custom application based on 3D Slicer core (the approach that many companies are taking now).

Thank you Andras this is exactly what I’m looking for!

Forgive the idiotic question, but it seems like incorporating the outline-generating filter into my code is going to be difficult, as vtkImageLabelOutline seems to depend on other slicer-specific classes. Unfortunately I’m adding contouring tools to an already-existing application, so at this point rebasing it off 3D slicer core seems unrealistic. Should I just try copying over the class, as well as all the classes it includes, and all the classes they include, etc?


Yes, there are a few more VTK filters that you need to take, too. I don’t think there is anything Slicer-specific.