# How to convert NIFTI or DICOM images into 3D mesh by using ITK?

**URL:** <https://discourse.itk.org/t/how-to-convert-nifti-or-dicom-images-into-3d-mesh-by-using-itk/4265>\
**Category:** Beginner Questions\
**Tags:** mesh\
**Created:** [July 14, 2021, 2:13pm UTC](https://discourse.itk.org/t/how-to-convert-nifti-or-dicom-images-into-3d-mesh-by-using-itk/4265 "2021-07-14T14:13:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Truring](https://discourse.itk.org/user_avatar/discourse.itk.org/truring/32/2171_2.png) [@Truring](https://discourse.itk.org/u/Truring)\
**Post date:** [July 14, 2021, 2:13pm UTC](https://discourse.itk.org/t/how-to-convert-nifti-or-dicom-images-into-3d-mesh-by-using-itk/4265/1 "2021-07-14T14:13:02Z")

</div>

I’m using ITK for spine reconstruction. I have some spine segmentation images in NIFTI format, how can I use ITK to reconstruct 3D spine mesh from these segmentation nifti images?

 ![image](https://discourse.itk.org/uploads/default/original/2X/f/f83209d51b5fbe3298258fa7bc73a8315f3203d6.png)

---

<div class="post-metadata">

**Author:** ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)\
**Post date:** [July 14, 2021, 2:16pm UTC](https://discourse.itk.org/t/how-to-convert-nifti-or-dicom-images-into-3d-mesh-by-using-itk/4265/2 "2021-07-14T14:16:03Z")

</div>

See this [example](https://itk.org/ITKExamples/src/Core/Mesh/ExtractIsoSurface/Documentation.html) and [BinaryMask3DMeshSource](https://itk.org/Doxygen/html/classitk_1_1BinaryMask3DMeshSource.html)’s documentation.

---

<div class="post-metadata">

**Author:** ![lassoan](https://discourse.itk.org/user_avatar/discourse.itk.org/lassoan/32/27_2.png) [@lassoan](https://discourse.itk.org/u/lassoan)\
**Post date:** [July 15, 2021, 8:41pm UTC](https://discourse.itk.org/t/how-to-convert-nifti-or-dicom-images-into-3d-mesh-by-using-itk/4265/3 "2021-07-15T20:41:07Z")

</div>

In the example I was surprised to see this mesh:

 ![image](https://discourse.itk.org/uploads/default/original/2X/8/84b0caba6706d76f87ebde82ba6cd06bd1852f97.jpeg)

This does not look pretty. I see that the voxels are very large, but regardless of that, the constructed surface must be smooth. It seems that a very important step is missing from this example: reconstruction of the continuous signal from the discrete samples. It can be either done by processing the image before the meshing (for example, using simple low-pass filtering or some level-set based reconstruction); or can be done by smoothing the resulting mesh.

@dzenanz What ITK image or mesh filters would you recommend to reconstruct a better quality surface?

---

<div class="post-metadata">

**Author:** ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)\
**Post date:** [July 15, 2021, 8:43pm UTC](https://discourse.itk.org/t/how-to-convert-nifti-or-dicom-images-into-3d-mesh-by-using-itk/4265/4 "2021-07-15T20:43:41Z")

</div>

The usual choice is [ITKCuberille](https://github.com/InsightSoftwareConsortium/ITKCuberille) remote module. It needs a padding filter if the object touches the edges, or else it crashes.

---

<div class="post-metadata">

**Author:** ![lassoan](https://discourse.itk.org/user_avatar/discourse.itk.org/lassoan/32/27_2.png) [@lassoan](https://discourse.itk.org/u/lassoan)\
**Post date:** [July 17, 2021, 10:29pm UTC](https://discourse.itk.org/t/how-to-convert-nifti-or-dicom-images-into-3d-mesh-by-using-itk/4265/5 "2021-07-17T22:29:44Z")

</div>

We recently wanted to generate quadrilateral mesh to use it in finite-element modeling as a shell (because they are more deformable than triangular meshes). It would be interesting to try if the ITKCuberille module can be used for this, but I could not find any Python examples (not even C++ examples, but I would prefer Python for quick testing anyway). I’ve checked:

- [GitHub - InsightSoftwareConsortium/ITKCuberille: Cuberille Implicit Surface Polygonization for ITK](https://github.com/InsightSoftwareConsortium/ITKCuberille)
- [https://www.insight-journal.org/browse/publication/740](https://www.insight-journal.org/browse/publication/740)
- [https://itk.org/ItkSoftwareGuide.pdf](https://itk.org/ItkSoftwareGuide.pdf)
- [https://itk.org/ITKExamples/index.html](https://itk.org/ITKExamples/index.html)

---

<div class="post-metadata">

**Author:** ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)\
**Post date:** [July 17, 2021, 11:34pm UTC](https://discourse.itk.org/t/how-to-convert-nifti-or-dicom-images-into-3d-mesh-by-using-itk/4265/6 "2021-07-17T23:34:07Z")

</div>

Here is a Python example:

> <https://github.com/dzenanz/HASI/blob/3d9617d8834a07d639e3f7260aad8e62a867db58/src/hasi/segmentation_pipeline.py#L197-L206>

It is currently in a WIP branch in my fork, but it should eventually make it into [GitHub - KitwareMedical/HASI: High-throughput Applications for Skeletal Imaging](https://github.com/KitwareMedical/HASI).
