New Python package for Slicer interoperability

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, a standalone Python package for reading/writing Slicer data files:

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

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

3 Likes

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

Probably this is an RAS-LPS issue or other coordinate system issue. Post data or screenshots if you need further advise.

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