.vtp to segmentation & load segmentation in Python

Hi,

I saved my segmentation as .vtp. Is there anyway to convert it back to Segmentation (.nrrd probably) in python or using 3D Slicers existing tools.

Moreover, I am trying to load segmentation data into 3D matrix in Python for analysis with the volume I used to do the segmentation.

I wonder if these can be done. Thank you for all of your help.

You can use Import section of Segmentations module. You can specify spacing, axis direction, and origin position by choose a reference volume (click on Representations / Binary labelmap / Update, then click the conversion path, and click “Set geometry from volume”; you may enter oversampling factor > 1 to increase resolution).

You can get voxels of a segment as a numpy array using slicer.util.arrayFromSegment. You can also export the entire segmentation to a labelmap volume and access its voxels using slicer.util.arrayFromVolume.

1 Like