Create .seg.nrrd file outside of slicer

We have a number of OCT with segmentation data done with legacy systems. I would like to convert the OCT files are DICOM files and they load mostly alright. They are loaded by drag and drop and selecting volume. The .nrrd files that I created are also loaded with drag and drop with segmentation selected. The three surfaces contained in the .nrrd files are displayed. The three surfaces can be viewed and edited in the segmentation editor. The .nrrd file had 4 dimension. A volume for each surface.

We would like to have the segments loaded with a name for each surface and a defined color. I created a .seg.nrrd file. When this file is dragged and dropped into slicer, segmentation is now the default option. But the three surface are not displayed. The segmentation editor does show one row with a default name. The following is the header for the .seg.nrrd file I created. I would like to know what else is needed for the names and colors to load properly. Note, the only difference between the .nrrd header and the .seg.nrrd header are the lines that start with Segment

# This NRRD file was generated by pynrrd
# on 2023-10-13 19:13:20(GMT).
# Complete NRRD file format specification at:
type: uint8
dimension: 4
sizes: 3 512 496 97
encoding: gzip
Segmentation_MasterRepresentation:=Binary labelmap
segment0_Color:=1.0 0.4980392156862745 0.054901960784313725
segment1_Color:=0.12156862745098039 0.4666666666666667 0.7058823529411765
segment2_Color:=0.6823529411764706 0.7803921568627451 0.9098039215686274

Please provide a complete example (.seg.nrrd file or .seg.nhdr+raw file) and we can have a look.

This is medical data. I have to have permission to share the file. I have asked. I will let you know when I hear.

You might find the following thread helpful: .seg.nrrd versus .nrrd

Also, here is the documentation page on the .seg.nrrd format: Segmentations — 3D Slicer documentation

One quick suggestion, might the tags be case-sensitive? On the documentation page it looks like the SegmentN_... tags all start with a capital “S”.

1 Like

I have permission to send the .seg.nrrd file. But the upload button says that it is not an accepted type. How would you like me to get you this file?

Thanks. I will make the change and see if that takes care of it.

@mikebind Good catch, probably that’ll fix it.

If not, then you can upload the data set anywhere (dropbox, onedrive, …) and post the download link here. You don’t need to upload real data, it can be some scribbles that you draw or some public/sample data.

Note that you can use the slicerio Python package to read segmentation files outside Slicer and I’ve been meaning to add segmentation writing as well. Since you are already developing a script that creates segmentation files, it would be great if you could contribute your script to this package. It does not have to be perfect to be useful, it just has to work and should be simple enough to use.

Lassoan and Mike,
Thanks. Changing to cap S worked. Sorry to have bothered you with some so simple.


No worries! Glad it was an easy fix!

Hi @lassoan,
I have many nrrd files (2000+) that are all the same 3D spatial area, with binary representations for the presence or absence of different features stored in their 4th dimension. I am hoping to create a single seg.nrrd file with each of the unique features stored in a segment. Is this possible and was there ever anything created to help write segmentation files?
I’d be grateful for your thoughts and guidance on this.

You can write a simple Python script (probably ChatGPT or Copilot can write it for you) that iterates through all the files uses pynrrd to read the header and add the appropriate metadata so that Slicer can read them correctly as segmentation. Slicer supports storing segmentations in a 4D volume. The volume index is referred to as “layer” and within the layer you can specify the meaning of each label value. The full specification of the file format is in the links above.