How to write a custom Tag to an image (NRRD or other) header

While two years ago, allow me to add information to make the post more self-contained: the behaviour of := is as expected.

This is a problem which was also of interest to me: in PET images you want to keep both the raw data as the way of translating it to SUV values. For this you might want to keep some of the DICOM tags instead of storing them in a different file. := is indeed correct (see the documentation). There are several other applications where one wants to do this. For instance mammography has a complete set of lookup tables associated to the images which one might want to preserve.

Each of the “< field >: < desc >” lines specifies information about one of the fields in the nrrd. (…)
Each of the “< key >:=< value >” lines specifies a key/value pair in the nrrd. (…)