How to save dicom image or segmentation mask to a .py file or .nii file?

I used the “segment editor” to get the bone tissue just now. and then I need save the segmentation mask to a .py file. I did not find how to do it in GUI, so I tried to do it with python script.I tried to get the data from node and save the numpy array to .py file. but i found seems there is not data array in the saved test.py file. here is the python code :
import numpy as np
bone_arr = np.array(‘Segment_1’)#Segment_1 is the bone mask
np.save(‘d:\test.npy’,bone_arr)
And then I tried to use “savenode” save the segmentation node to .py file. But I failed, seems the node can not be saved as .py file. And I do not know how to get the data array (segmentation)from the node easily in python script.Or can i save the segmentation mask to the .nii or .py file in GUI?
thank you in advance.

You need to export to a labelmap first, which you can do in the Segmentations module panel shown below. Then you can do:

>>> a = array("Segmentation-label")
>>> numpy.save('/tmp/x.py', a)

image

Your answer works. Thanks a lot.

Bump…
Loading two nii.gz (volume and segmentation(only 1 segment)).

Modifying the segmentation.
Converting to binary labelmap.
Export to file (.nii.gz).

Exported file is much smaller than the volume/orig segmentation.
Seems to be limited by the segmentation bounding box.

Is it possible to export the segmentation with the original dimensions. (ie compatable with pyradiomics)?

Saving the full dimensions should be the default now, so try with the latest version.

Ughhh… Thank you…

I cannot duplicate it today.
But I have a bunch of cropped segmentations from yesterday…

Not sure how it happened, but it did…
Was able to reset the geometry one by one…