# .vtp to segmentation & load segmentation in Python

**URL:** <https://discourse.slicer.org/t/vtp-to-segmentation-load-segmentation-in-python/2883>\
**Category:** Support\
**Created:** [May 22, 2018, 5:37pm UTC](https://discourse.slicer.org/t/vtp-to-segmentation-load-segmentation-in-python/2883 "2018-05-22T17:37:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![trnhx001](https://avatars.discourse-cdn.com/v4/letter/t/ed655f/32.png) [@trnhx001](https://discourse.slicer.org/u/trnhx001)\
**Post date:** [May 22, 2018, 5:37pm UTC](https://discourse.slicer.org/t/vtp-to-segmentation-load-segmentation-in-python/2883/1 "2018-05-22T17:37:17Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [May 22, 2018, 6:20pm UTC](https://discourse.slicer.org/t/vtp-to-segmentation-load-segmentation-in-python/2883/2 "2018-05-22T18:20:33Z")

</div>

> [@trnhx001](#):
>
> 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.

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).

> [@trnhx001](#):
>
> I am trying to load segmentation data into 3D matrix in Python for analysis with the volume I used to do the segmentation.

You can get voxels of a segment as a numpy array using [`slicer.util.arrayFromSegment`](https://github.com/Slicer/Slicer/blob/master/Base/Python/slicer/util.py#L810-L815). You can also export the entire segmentation to a labelmap volume and access its voxels using `slicer.util.arrayFromVolume`.
