# Prevent slicer overwritting nrrd header.

**URL:** <https://discourse.slicer.org/t/prevent-slicer-overwritting-nrrd-header/29601>\
**Category:** Support\
**Tags:** segmentation\
**Created:** [May 23, 2023, 11:11am UTC](https://discourse.slicer.org/t/prevent-slicer-overwritting-nrrd-header/29601 "2023-05-23T11:11:09Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mmonteiro](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mmonteiro/32/18662_2.png) [@mmonteiro](https://discourse.slicer.org/u/mmonteiro)\
**Post date:** [May 23, 2023, 11:11am UTC](https://discourse.slicer.org/t/prevent-slicer-overwritting-nrrd-header/29601/1 "2023-05-23T11:11:10Z")

</div>

Hello,

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,

---

<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 23, 2023, 11:42am UTC](https://discourse.slicer.org/t/prevent-slicer-overwritting-nrrd-header/29601/2 "2023-05-23T11:42:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mmonteiro](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mmonteiro/32/18662_2.png) [@mmonteiro](https://discourse.slicer.org/u/mmonteiro)\
**Post date:** [May 23, 2023, 12:48pm UTC](https://discourse.slicer.org/t/prevent-slicer-overwritting-nrrd-header/29601/3 "2023-05-23T12:48:51Z")

</div>

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.

---

<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 23, 2023, 1:26pm UTC](https://discourse.slicer.org/t/prevent-slicer-overwritting-nrrd-header/29601/4 "2023-05-23T13:26:27Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mmonteiro](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mmonteiro/32/18662_2.png) [@mmonteiro](https://discourse.slicer.org/u/mmonteiro)\
**Post date:** [May 23, 2023, 2:16pm UTC](https://discourse.slicer.org/t/prevent-slicer-overwritting-nrrd-header/29601/5 "2023-05-23T14:16:56Z")

</div>

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

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

```

However, after going through slicer Segment0\_Tags gets overwritten to

```python
OrderedDict([...
             ('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'),
             ('Segment0_Tags',
              '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,

```auto

```

---

<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 23, 2023, 10:08pm UTC](https://discourse.slicer.org/t/prevent-slicer-overwritting-nrrd-header/29601/6 "2023-05-23T22:08:56Z")

</div>

The specification is available here:

[https://slicer.readthedocs.io/en/latest/developer\_guide/modules/segmentations.html#segment-custom-fields](https://slicer.readthedocs.io/en/latest/developer_guide/modules/segmentations.html#segment-custom-fields)

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

---

<div class="post-metadata">

**Author:** ![mmonteiro](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mmonteiro/32/18662_2.png) [@mmonteiro](https://discourse.slicer.org/u/mmonteiro)\
**Post date:** [May 24, 2023, 8:37am UTC](https://discourse.slicer.org/t/prevent-slicer-overwritting-nrrd-header/29601/7 "2023-05-24T08:37:04Z")

</div>

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.
