# ITK image to mesh to vtk polydata

**URL:** https://discourse.slicer.org/t/itk-image-to-mesh-to-vtk-polydata/12717
**Category:** Development
**Tags:** extensions-manager, python
**Created:** [July 24, 2020, 3:40am UTC](https://discourse.slicer.org/t/itk-image-to-mesh-to-vtk-polydata/12717 "2020-07-24T03:40:18Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Zhiy](https://avatars.discourse-cdn.com/v4/letter/z/0ea827/32.png) [@Zhiy](https://discourse.slicer.org/u/Zhiy)
#### Post date: [July 24, 2020, 3:40am UTC](https://discourse.slicer.org/t/itk-image-to-mesh-to-vtk-polydata/12717/1 "2020-07-24T03:40:18Z")

</div>

Dear all,

Recently I am trying to extract the surface geometry from a binary ITK image (resulting from ostu\_threshold\_image\_filter) into ITK mesh. Then convert this ITK MESH to a vtk polydata.

The filters I used include BinaryThresholdImageFilter, BinaryMask3DMeshSource and MeshToPolyDataFilter. I program in python. The result turns out to be of type itk.itkPolyDataPython.itkPolyDataF instead of expected vtkPolyData.

Moreover, I am not sure the result of BinaryMask3DMeshSource output a triangle mesh. Could anyone kindly provide some advise?

Appreciate.

Thanks,

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [July 24, 2020, 6:03am UTC](https://discourse.slicer.org/t/itk-image-to-mesh-to-vtk-polydata/12717/2 "2020-07-24T06:03:17Z")

</div>

ITK’s mesh infrastructure is still quite far behind VTK (similarly how VTK’s image processing capabilities are much more limited compared to ITK), so I would recommend to use VTK for mesh processing and ITK for image processing. I don’t think there is a functional ITK-VTK glue package available for Python, so if you would want to pass data between ITK and VTK then you may need to write/read files or implement serialization to/from numpy arrays (but check with Kitware folks before you invest too much time into implementing numpy serialization, as maybe there is already some ongoing effort that you can join).

Anyway, most likely you won’t need to implement low-level features from scratch. All the features that you described (and much more sophisticated segmentation methods) are already all conveniently available in segmentations infrastructure and in segment editor effects. You can access these features via GUI ([Segmentations and Segment Editor module](https://slicer.readthedocs.io/en/latest/user_guide/image_segmentation.html)) or from Python scripting (see [script repository](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#How_to_run_segment_editor_effects_from_a_script) for examples).

---

<div class="post-metadata">

### Author: ![Zhiy](https://avatars.discourse-cdn.com/v4/letter/z/0ea827/32.png) [@Zhiy](https://discourse.slicer.org/u/Zhiy)
#### Post date: [July 24, 2020, 2:59pm UTC](https://discourse.slicer.org/t/itk-image-to-mesh-to-vtk-polydata/12717/3 "2020-07-24T14:59:49Z")

</div>

Thanks for your reply.

I work around by writing/reading files between ITK/VTK meshes.
