vtkSegmentation data to niftii conversion

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…!!!

Please go to the “Segmentations” module

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

image

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 ?

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

This thread may help, see here.