and other tags mentioned above (IntensityRange and InterceptSlope) do not even exist in the output.
Is there a actually way, how I can address that (preferably in python)? I did see vtkMetaImageReader.GetInformation() but was not quite sure how to use it, https://vtk.org/doc/nightly/html/classvtkInformation.html did not describe how to actually even get key names etc.
The GetInformation() method doesn’t give you the information you want, it returns information related to pipeline execution and is unrelated to the file header. The vtkMetaImageReader does not, in fact, read those tags. I don’t think anyone has any plans to add them.
But the meta header is just text, and easy to read in Python. This should get you started, though you’ll have to handle the string-to-number conversions:
meta = {} # dictionary to store the header in
with open(filename) as f:
for line in f.readlines():
tag, values = line.split('=', 1)
tag = tag.strip()
values = [v.strip() for v in values.split()]
meta[tag] = values
if tag == "ElementDataFile":
break
Yes, after vtkMetaImageWriter writes the file, you can use Python to rewrite the header with the extra information. Use an ordered dict and make sure ElementDataFile comes last:
import collections
meta = collections.OrderedDict()
There’s also a metaimageio Python module (not in VTK, but on github and pypi), but I’ve never used it.