how to load mrb file and save all nodes in nii format using script

Operating system: windows 10
Slicer version:4.8.1
Expected behavior: save nodes in nii format using script
Actual behavior: only can save in nrrd format

I want to export image and labelmap node in nii format to a directory using python script.
My script is:

outdir = r’D:\output_dir’

However, this could only save node in nrrd format, the 3D Slicer default format. How could I save my image node and labelmap node in nii format?

Thanks a lot.

You can iterate through all the image nodes and save them to any folder using any of the supported file extensions. Something like this:

for volumeNode in slicer.util.getNodesByClass("vtkMRMLScalarVolumeNode"):
  slicer.util.saveNode(volumeNode, "c:/tmp/" + volumeNode.GetName() + ".nii")
1 Like

Thank you very much, Andras. It works well.

1 Like