# Adding custom metadata during a filtering pipeline

**URL:** <https://discourse.itk.org/t/adding-custom-metadata-during-a-filtering-pipeline/3261>\
**Category:** Engineering\
**Created:** [July 3, 2020, 5:47am UTC](https://discourse.itk.org/t/adding-custom-metadata-during-a-filtering-pipeline/3261 "2020-07-03T05:47:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Steve\_Moore](https://discourse.itk.org/user_avatar/discourse.itk.org/steve_moore/32/1609_2.png) [@Steve\_Moore](https://discourse.itk.org/u/Steve_Moore)\
**Post date:** [July 3, 2020, 5:47am UTC](https://discourse.itk.org/t/adding-custom-metadata-during-a-filtering-pipeline/3261/1 "2020-07-03T05:47:43Z")

</div>

Hi

I have a situation where I need to create some custom filters (derived from an itk::ImageToImageFilter) that modify an input image, but I also want to keep track of some metadata generated by one filter (e.g: a std::vector) that will be used later on by another filter. It seems that this could be handled by accessing and adding to a MetaDataDictionary inside a filter’s GenerateData() method doing something like:

auto outputDict = outputPtr-\>GetMetaDataDictionary();  
itk::EncapsulateMetaData(outputDict, “Float”, float(1.0));

(for a trivial case of just inserting a float into the dictionary). What I’m finding is that none of the additions to the dictionary get carried through to the output. I imagine that I’m missing some important steps, but can’t find much documentation on this particular topic. Any advice would be much appreciated. A test program is attached.

Steve

[TestITKMetaData.cpp](https://discourse.itk.org/uploads/short-url/oGNYEVUGXzGbX9dn862qF9pDGsH.cpp) (4.3 KB)

---

<div class="post-metadata">

**Author:** ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)\
**Post date:** [July 14, 2020, 4:33pm UTC](https://discourse.itk.org/t/adding-custom-metadata-during-a-filtering-pipeline/3261/2 "2020-07-14T16:33:25Z")

</div>

Hello @Steve_Moore!

Welcome to the ITK Community ☀

Thanks for the nice, self-contained example.

It looks like the code is mostly correct, but the compiler is making the undesired choice in the returned MetaDataDictionary with `auto` – we can be explicit with out desired output by changing

```auto
auto outputDict = outputPtr->GetMetaDataDictionary();

```

to

```auto
itk::MetaDataDictionary & outputDict = outputPtr->GetMetaDataDictionary();

```

[CMakeLists.txt](https://discourse.itk.org/uploads/short-url/etsGDnWNRK9c4U8bgW1iQbjQA6E.txt) (220 Bytes) [TestITKMetaData.cpp](https://discourse.itk.org/uploads/short-url/4fr7T6KiKzpLBCZrVz7EG0EN47K.cpp) (4.5 KB)

---

<div class="post-metadata">

**Author:** ![Steve\_Moore](https://discourse.itk.org/user_avatar/discourse.itk.org/steve_moore/32/1609_2.png) [@Steve\_Moore](https://discourse.itk.org/u/Steve_Moore)\
**Post date:** [July 15, 2020, 2:59am UTC](https://discourse.itk.org/t/adding-custom-metadata-during-a-filtering-pipeline/3261/3 "2020-07-15T02:59:49Z")

</div>

Thanks so much Matt. That worked perfectly!
