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

**URL:** https://discourse.vtk.org/t/how-to-render-the-pixel-contour-of-an-image-follow-up/463
**Category:** Support
**Created:** [March 12, 2019, 3:44pm UTC](https://discourse.vtk.org/t/how-to-render-the-pixel-contour-of-an-image-follow-up/463 "2019-03-12T15:44:21Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Harry](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/h/f6c823/32.png) [@Harry](https://discourse.vtk.org/u/Harry)
#### Post date: [March 12, 2019, 3:44pm UTC](https://discourse.vtk.org/t/how-to-render-the-pixel-contour-of-an-image-follow-up/463/1 "2019-03-12T15:44:21Z")

</div>

I have a follow-up question to this thread: [https://public.kitware.com/pipermail/vtkusers/2011-June/068268.html](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,  
Harry

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [March 12, 2019, 4:52pm UTC](https://discourse.vtk.org/t/how-to-render-the-pixel-contour-of-an-image-follow-up/463/2 "2019-03-12T16:52:00Z")

</div>

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

> <https://github.com/Slicer/Slicer/blob/master/Libs/MRML/Logic/vtkImageLabelOutline.h>

Labelmap image overlaid as is:

 ![image](https://discourse.vtk.org/uploads/default/original/1X/72aa95187e74b513c06e05df0e6b843a064f11e9.jpeg)

Labelmap image overlaid with vtkImageLabelOutline filter applied:

 ![image](https://discourse.vtk.org/uploads/default/original/1X/b9bb48904c5e48738ea410ea88c9b9943c11e9fb.png)

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.

 ![image](https://discourse.vtk.org/uploads/default/original/1X/a272dd54117ee682d97d4826c4dcecb54ed8383d.jpeg)

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:

 ![image](https://discourse.vtk.org/uploads/default/original/1X/2a5070d0edd26cbae2f4b5c6f913520f8e789d86.png)

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](https://github.com/Slicer/Slicer/blob/master/Modules/Loadable/Segmentations/MRMLDM/vtkMRMLSegmentationsDisplayableManager2D.cxx). 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).

---

<div class="post-metadata">

### Author: ![Harry](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/h/f6c823/32.png) [@Harry](https://discourse.vtk.org/u/Harry)
#### Post date: [March 12, 2019, 6:59pm UTC](https://discourse.vtk.org/t/how-to-render-the-pixel-contour-of-an-image-follow-up/463/3 "2019-03-12T18:59:51Z")

</div>

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?

Thanks,  
Harry

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [March 13, 2019, 12:02am UTC](https://discourse.vtk.org/t/how-to-render-the-pixel-contour-of-an-image-follow-up/463/4 "2019-03-13T00:02:54Z")

</div>

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