# New Python package for Slicer interoperability

**URL:** <https://discourse.slicer.org/t/new-python-package-for-slicer-interoperability/17850>\
**Category:** Development\
**Tags:** segmentation, python\
**Created:** [May 29, 2021, 5:21am UTC](https://discourse.slicer.org/t/new-python-package-for-slicer-interoperability/17850 "2021-05-29T05:21:09Z")\
**Posts on this page:** 4\
**Page:** 1

<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 29, 2021, 5:21am UTC](https://discourse.slicer.org/t/new-python-package-for-slicer-interoperability/17850/1 "2021-05-29T05:21:09Z")

</div>

We often find that Slicer-generated data sets needs to be accessed or created outside of Slicer’s Python environment. While we try to use standard file formats, there are often small customizations and additional metadata that requires a little effort to manage. To make this a bit easier for users, I’ve created [slicerio](https://github.com/lassoan/slicerio), a standalone Python package for reading/writing Slicer data files:

> **[slicerio](https://pypi.org/project/slicerio/)**
>
> Utilities for 3D Slicer

For now, I have only added .seg.nrrd file reading and basic writing. For example, segment metadata can be accessed like this (in any Python environment, after `pip install slicerio`):

```auto
>>> import slicerio
>>> segmentation_info = slicerio.read_segmentation_info("Segmentation.seg.nrrd")
>>> segment_names
['ribs', 'cervical vertebral column', 'thoracic vertebral column', 'lumbar vertebral column', 'right lung', 'left lung', 'tissue']
>>> segment = slicerio.segment_from_name(segmentation_info, segment_names[3])
>>> segment["labelValue"]
4
>>> segment["color"]
[0.831373, 0.737255, 0.4]

```

In the future we could add utilities for managing markups files (convert json to/from csv and numpy arrays), tables (read/write schema.csv files), etc.

Any comments and suggestions are welcome. If you have Python code snippets that could be useful in this context then feel free to send pull requests.

---

<div class="post-metadata">

**Author:** ![Francesca\_Lo\_Iacono](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/francesca_lo_iacono/32/13557_2.png) [@Francesca\_Lo\_Iacono](https://discourse.slicer.org/u/Francesca_Lo_Iacono)\
**Post date:** [November 22, 2022, 9:35am UTC](https://discourse.slicer.org/t/new-python-package-for-slicer-interoperability/17850/2 "2022-11-22T09:35:23Z")

</div>

Hi! I am developing an automatic segmentation algorithm in python but the obtained segmentation do not overlap in Slicer with the original images, how can I use this package to make it happens?

thank you

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [November 22, 2022, 6:24pm UTC](https://discourse.slicer.org/t/new-python-package-for-slicer-interoperability/17850/3 "2022-11-22T18:24:32Z")

</div>

Probably this is an RAS-LPS issue or other [coordinate system](https://www.slicer.org/wiki/Coordinate_systems) issue. Post data or screenshots if you need further advise.

---

<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:** [November 22, 2022, 8:48pm UTC](https://discourse.slicer.org/t/new-python-package-for-slicer-interoperability/17850/4 "2022-11-22T20:48:54Z")

</div>

Have you set the origin, spacing, axis directions for the segmentation that you created?
