How to read EXR metadata/header attribs?

   4732   8   1
User Avatar
Member
207 posts
Joined: Nov. 2015
Offline
Hi;

Is there any mechanism at all in Houdini to read EXR header attributes?

Ideally I would like to read a numeric custom attribute and do something with it. Python is appealing, but installing OpenEXR or OIIO into Hython is less so.

Thanks!
User Avatar
Member
8041 posts
Joined: Sept. 2011
Offline
if you don't mind going the COPs route, you can use python copNode methods to get metadata.

copNode.getMetadataString() probably being the main one

there's also the metadata cop vop, but I'm not sure how useful that would be since it would only be able to influence pixel values.
Edited by jsmack - June 28, 2022 01:17:59
User Avatar
Staff
2638 posts
Joined: July 2005
Offline
You can also use `iinfo -v foo.exr` to read all the metadata. In a future version of Houdini there's also the `-J` option to output in JSON.

Houdini also ships with hoiiotool(a version of OIIO tool compiled against the Houdini version of OIIO).
Edited by mark - June 28, 2022 08:46:15
User Avatar
Member
207 posts
Joined: Nov. 2015
Offline
mark
Houdini also ships with hoiiotool(a version of OIIO tool compiled against the Houdini version of OIIO).

Awesome! I *thought* I knew houdini shipped with some version of OIIO! But, are python bindings included? If I try importing OpenImageIO in a python node, I see errors, so I assumed I was misremembering that it existed.
Edited by dhemberg - June 28, 2022 10:00:45
User Avatar
Member
32 posts
Joined: Aug. 2011
Offline
dhemberg
mark
Houdini also ships with hoiiotool(a version of OIIO tool compiled against the Houdini version of OIIO).

Awesome! I *thought* I knew houdini shipped with some version of OIIO! But, are python bindings included? If I try importing OpenImageIO in a python node, I see errors, so I assumed I was misremembering that it existed.

Did you ever manage to get anything working with this? I'm looking to embed some exr metadata in my images.
User Avatar
Member
207 posts
Joined: Nov. 2015
Offline
Hi; I did, though it is pretty ugly. I used the approach @jsmack offered, as I never heard back about python bindings and oiiotool in Houdini. So, here is what I do:

--I make a COP2 network (mine lives in LOPS)
--File read the image I want metadata from
--In LOPS, I make a Python node
--I use python to get the COP2 file node, then use getMetaDataString() to read the full metadata header from the COP2 node.
--this returns a dictionary, I'm interested in the metadata attribute, e.g.

then proceed accordingly. I don't like this; if I can just read the metadata directly without having to go through COPS for the image reader, that would be much better.
User Avatar
Member
32 posts
Joined: Aug. 2011
Offline
Ah, I could never read any of the metadata in the python script. I was trying to query the rendertime from a karma render, but:

node = hou.node("/obj/cop2net/file")
node.getMetaDataString("renderTime")

The second one never returned any metadata but I can read that string in nuke. Was that similar metadata to what you were reading?
User Avatar
Member
207 posts
Joined: Nov. 2015
Offline
I was querying an attribute called "whiteLuminance"; when I middle mouse on my file, I see this:



When I load a recent Karma render and middle mouse on it, I see:



Is it the case that your python should be asking for "renderTime_s" rather than "renderTime"?

EDIT: Also, here is my Python; note that I first ask for "Attributes", then parse that:

# This is a shenanigan to read the "whiteLuminance"
# attribute from my hand-made IBL texture, and set the
# intensity on my light accordingly. 

import ast
this_node = hou.pwd()
ibl_reader = hou.node(this_node.evalParm("ibl_cop")) #path to my COP2 file reader

# The ast module casts a string as a dictionary, 
# which is how Houdini represents exr metadata.
metadata = ast.literal_eval(ibl_reader.getMetaDataString('attributes'))

# Read the attribs I'm interested in.
whiteLuminance = metadata['whiteLuminance']
measuredLux = metadata['MeasuredLUX']
Edited by dhemberg - Oct. 17, 2022 10:44:01

Attachments:
Screen Shot 2022-10-17 at 9.32.08 AM.png (48.7 KB)
Screen Shot 2022-10-17 at 9.33.36 AM.png (47.5 KB)

User Avatar
Member
32 posts
Joined: Aug. 2011
Offline
Ah, fantastic, thanks so much!

I was trying to directly read the MetaData name, but the name on the node is attributes.

import ast
# path to file node
node = hou.node("../render_file")
# convert string to dict
attrs = ast.literal_eval(node.getMetaDataString("attributes"))
# Print peak memory and render time
print(attrs["info:peakMemory_s"], attrs["renderTime_s"])
  • Quick Links