# vtkSegmentation data to niftii conversion

**URL:** <https://discourse.slicer.org/t/vtksegmentation-data-to-niftii-conversion/27003>\
**Category:** Development\
**Created:** [January 1, 2023, 5:19pm UTC](https://discourse.slicer.org/t/vtksegmentation-data-to-niftii-conversion/27003 "2023-01-01T17:19:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rajesh\_Ds](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rajesh_ds/32/16526_2.png) [@Rajesh\_Ds](https://discourse.slicer.org/u/Rajesh_Ds)\
**Post date:** [January 1, 2023, 5:19pm UTC](https://discourse.slicer.org/t/vtksegmentation-data-to-niftii-conversion/27003/1 "2023-01-01T17:19:37Z")

</div>

I have a vtkSegmentation data instance obtained as a segmentation results, using python code and slicer’s lungCT\_analyzer modules code. I would like to get the same in niftii format (i.e .nii.gz), so that I can visually analyze the segmentation results on some sample lung CT dataset and process these segmentations further. Any help would be highly appreciated please…!!!

---

<div class="post-metadata">

**Author:** ![rbumm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbumm/32/9404_2.png) [@rbumm](https://discourse.slicer.org/u/rbumm)\
**Post date:** [January 1, 2023, 8:10pm UTC](https://discourse.slicer.org/t/vtksegmentation-data-to-niftii-conversion/27003/2 "2023-01-01T20:10:57Z")

</div>

Please go to the “Segmentations” module

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/6/c/6ca109be5e9605f843f938d3a9ba4b7e848e7bec.png)

and under “Export to files” choose “NIFTI” and “Export”

![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/b/a/ba016f5c923ccf44f792d3b360e7a8a946cb39a4.png)

---

<div class="post-metadata">

**Author:** ![Rajesh\_Ds](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rajesh_ds/32/16526_2.png) [@Rajesh\_Ds](https://discourse.slicer.org/u/Rajesh_Ds)\
**Post date:** [January 2, 2023, 2:41am UTC](https://discourse.slicer.org/t/vtksegmentation-data-to-niftii-conversion/27003/3 "2023-01-02T02:41:26Z")

</div>

Thank you and the python code to do the same ? Do we have a python function under vtk libraries, to export vtk Segmentation type (made of multiple vtkImageObjectData type segments) data to niftii format ?

---

<div class="post-metadata">

**Author:** ![Rajesh\_Ds](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rajesh_ds/32/16526_2.png) [@Rajesh\_Ds](https://discourse.slicer.org/u/Rajesh_Ds)\
**Post date:** [January 2, 2023, 7:24am UTC](https://discourse.slicer.org/t/vtksegmentation-data-to-niftii-conversion/27003/4 "2023-01-02T07:24:43Z")

</div>

I have obtained the segmentation using the GetSegmentation() method from vtkSegmentation class

---

<div class="post-metadata">

**Author:** ![rbumm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbumm/32/9404_2.png) [@rbumm](https://discourse.slicer.org/u/rbumm)\
**Post date:** [January 2, 2023, 10:01am UTC](https://discourse.slicer.org/t/vtksegmentation-data-to-niftii-conversion/27003/5 "2023-01-02T10:01:09Z")

</div>

[This thread](https://discourse.slicer.org/t/overlapping-segmentions-export-to-nifti/15773) may help, [see here](https://discourse.slicer.org/t/overlapping-segmentions-export-to-nifti/15773/13).
