# How can I embed text in nrrd file?

**URL:** <https://discourse.slicer.org/t/how-can-i-embed-text-in-nrrd-file/22260>\
**Category:** Support\
**Tags:** mri\
**Created:** [March 2, 2022, 1:04pm UTC](https://discourse.slicer.org/t/how-can-i-embed-text-in-nrrd-file/22260 "2022-03-02T13:04:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sukhe](https://avatars.discourse-cdn.com/v4/letter/s/ccd318/32.png) [@Sukhe](https://discourse.slicer.org/u/Sukhe)\
**Post date:** [March 2, 2022, 1:04pm UTC](https://discourse.slicer.org/t/how-can-i-embed-text-in-nrrd-file/22260/1 "2022-03-02T13:04:23Z")

</div>

I want to embed text in the MRI nrrd file. Is there any method?  
Many thanks!

---

<div class="post-metadata">

**Author:** ![mikebind](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@mikebind](https://discourse.slicer.org/u/mikebind)\
**Post date:** [March 4, 2022, 9:39pm UTC](https://discourse.slicer.org/t/how-can-i-embed-text-in-nrrd-file/22260/2 "2022-03-04T21:39:27Z")

</div>

You can add custom fields to NRRD files. [Examples — pynrrd 0.4.2 documentation](https://pynrrd.readthedocs.io/en/latest/examples.html)

You could save your MRI to a .nrrd file in Slicer, and then load using pynrrd, then do something like this

```auto
import nrrd # load pynnrd package
img_data, img_header = nrrd.read('my_saved_mri.nrrd')
# Add the text you want to save to the header
img_header["my_custom_field1"] = "the text I want to save goes here"
my_custom_field_map = {"my_custom_field1": "str"} # python dict of custom field names and data types
nrrd.write('output_including_text.nrrd', img_data, img_header, custom_field_map=my_custom_field_map)

```
