save segmentation

There are two different approaches you can use.

A. Write your segmentation to numpy array directly in Slicer’s Python environment. You can use tools available in Slicer to preprocess, normalize, augment your data, using GUI, Python scripts, or Jupyter Notebooks. There is an example script here that shows how to do 3D image augmentation with random deformations in Slicer.

B. You can load the segmentation (.seg.nrrd) file and process it using any tools (e.g., torchio). Segmentation is stored in standard .nrrd file, so you can use any Python nrrd reader to read it as a numpy array. You can find specification of custom fields here and an example Python code snippet (that does not require Slicer’s Python environment) here.