Prevent slicer overwritting nrrd header.


I am trying to store some custom metadata in the nrrd header of my segmentation files. For example, the id of the annotator which segmented the file. The intended workflow is to:

  1. Load a nrrd segmentation file with custom header metadata into Slicer.
  2. Edit some segments.
  3. Save/Export the new segmentation file while keeping the custom metadata.

However, when I load a segmentation file into Slicer and export it again Slicer removes all metadata fields it does not recognise.

Is there a way of keeping the custom metadata while passing through Slicer?

Thanks for your help,

This would make sense. Instead of just passing through the data, it would be better to make the additional metadata available for reading/writing within Slicer. We already have this feature for each segment: for each segment you can store “tags” - a list of custom key/value pairs. Would it be OK if we added a single “Segmentation_tags” NRRD custom metadata field? The alternative would be to expose each unknown NRRD custom metadata field in a segmentation tag.

Thanks for your answer,

I noticed that even when passing metadata using the segment tags (e.g. Segment0_Tags), the metadata still gets overwritten by Slicer.

Segment tags are read from and written to the .seg.nrrd file. If you find that a tag is not preserved then maybe you did not use the correct format.

Maybe I misunderstood, this is my part of my header before going through slicer as printed by pynrrd using nrrd.read_header():

             ('Segment0_ID', 'c05184dc-408d-428e-a95a-ec1a22e56127'),
             ('Segment0_Name', 'left-lung'),
             ('Segment0_Layer', '0'),
             ('Segment0_LabelValue', '1'),
             ('Segment0_Tags', 'AnnotatorID|asdf|'),
              '0.06274509803921569 0.9098039215686274 0.7098039215686275'),

However, after going through slicer Segment0_Tags gets overwritten to

             ('Segment0_Color', '0.0627451 0.909804 0.709804'),
             ('Segment0_ColorAutoGenerated', '1'),
             ('Segment0_Extent', '0 98 0 67 0 27'),
             ('Segment0_ID', 'c05184dc-408d-428e-a95a-ec1a22e56127'),
             ('Segment0_LabelValue', '1'),
             ('Segment0_Layer', '0'),
             ('Segment0_Name', 'left-lung'),
             ('Segment0_NameAutoGenerated', '1'),
              'TerminologyEntry:Segmentation category and type - 3D Slicer General Anatomy list~SCT^85756007^Tissue~SCT^85756007^Tissue~^^~Anatomic codes - DICOM master list~^^~^^|'),

What is the correct format for Segment0_Tags that ensures that custom tags will be preserved?

Thanks in advance,

The specification is available here:

In your example the field was discarded because you haven’t specified any key:value pairs.

1 Like

Thank you for clarifying, that solved the issue.
For future reference, as long as you add tags as key:value| slicer will not discard them.