Adding custom metadata during a filtering pipeline

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 (4.3 KB)

1 Like

Hello @Steve_Moore!

Welcome to the ITK Community :sunny:

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 outputDict = outputPtr->GetMetaDataDictionary();

to

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

CMakeLists.txt (220 Bytes) TestITKMetaData.cpp (4.5 KB)

2 Likes

Thanks so much Matt. That worked perfectly!

1 Like