multi layer EXR

Hello,

I see in another post that in the future we will be able to set some parameters for outputting EXR files.

Does draft support multilayer EXR files? Is this planned?

Thanks in advance,

J.

Yes, some operations in Draft support multilayer EXR files. For example, Draft.Image.ReadFromFile() and Draft.Image.WriteToFile() read and write all layers in an EXR file, respectively.

What do you want to do with multilayer EXR files? We can give you more specific information once we know what you want to do.

Hi Paul,

I’d like to load in images from a render job into a stack and save them as a multilayered EXR.

J.

So, you’d be loading various images, and combining the layers into a single exr? So, you’d have image A with RGBA channels, and image B with RGBA channels, and you want to create an image C with A.R, A.G, A.B, A.A, B.R, B.G, B.B, B.A channels? Yup, that can be done. Some sample code:

[code]import Draft

imgA = Draft.Image.ReadFromFile( ‘A.exr’ )
imgB = Draft.Image.ReadFromFile( ‘B.exr’ )

for ch in [ ‘R’, ‘G’, ‘B’, ‘A’ ]:
imgA.RenameChannel( ch, ‘A.’ + ch )
imgB.RenameChannel( ch, ‘B.’ + ch )

imgC = Draft.Image.CreateImage( imgA.width, imgA.height, [ ‘A.R’, ‘A.G’, ‘A.B’, ‘A.A’, ‘B.R’, ‘B.G’, ‘B.B’, ‘B.A’ ] )
imgC.Copy( imgA, channels=[ ‘A.R’, ‘A.G’, ‘A.B’, ‘A.A’ ] )
imgC.Copy( imgB, channels=[ ‘B.R’, ‘B.G’, ‘B.B’, ‘B.A’ ] )
imgC.WriteToFile( ‘C.exr’ )[/code]
Let me know if you need assistance setting up a fancier script for use on general images, etc, in Deadline.

Cheers,
Andrea

Hi Andrea,

This is a great help. I’m going to play around with this and will let you know how I get on.

Thank you very much!

Josh.

You’re welcome!

First off, I apologize if this a duplicate post. I swear I posted my question in here, but it seems to have disappeared.

I am wondering if there is a way to go the opposite way. In other words, if I render an EXR sequence that has 20 layers, can Draft run those individual layers to PNG sequences?

Thanks!

Yup, basically just do the steps in reverse… read in the exr, make an image with the same channels as those you want to extract, copy those channels, rename them to the standard RGB(A) names, then write out the image. Repeat the create/copy/rename/write steps until you’ve got all the channels. Let me know if that makes sense, or you need more details.

Cheers,
Andrea

Thanks for the response! It looks like (based on that snipet of code) that I would need to know the exact name of each layer and manually write in the name of the layer I want it to output.

We use C4D and Vray for nearly all of our renders. Unfortunately they don’t necessarily play very nice together when it comes to naming multilayered multi-pass files. I have attached a screen grab of an example from a recent project. These change with every project, so there is little to no consistency with the naming. For instance, the Lighting pass will always be called “Lighting” but with each project, it will always have a different number attached to the beginning. Sometimes it will be “_0014_Lighting” other times it will be “_0003_Lighting”.

Is there a way to have it detect all the layers and then populate the name of the png with it? If so, can it take it one step further and delete all the “_####” at the beginning of each layer?

Thanks again for your help!

Hi,

Maybe this will help, you can inspect what layers are in the EXR;

currinFile = ReplaceFilenameHashesWithNumber( inFilePattern, frameNumber ) #will remove the hashes and replace with a filename baseRGB = Draft.Image.ReadFromFile( currinFile ) #Load the image file channellist = baseRGB.GetChannelNames() #list the existing channels print "Existing channels:", channellist

Will return;
Existing channels: [‘RGB.A’, ‘RGB.B’, ‘RGB.G’, ‘RGB.R’]

To remove the numbers before the layer names you could;

elementnames=[]
for i in range( 0, len( channellist ) ):
	element = channellist[i].split( "_" )
	elementnames.append( element[ len( element ))

And then;

for i in range( 0, len( channellist ), 4 ): EXRoutput = Draft.Image.CreateImage( baseRGB.width, baseRGB.height, ([elementnames[i], elementnames[i+1], elementnames[i+2], elementnames[i+4] )) #Create a new image using the channel list. EXRoutput.Copy( baseRGB, channels=[elementnames[i], elementnames[i+1], elementnames[i+2], elementnames[i+4]) #copy the desired channels into the new image currOutFile = ReplaceFilenameHashesWithNumber( outFilenamebase, frameNumber ) #prepare the output filename EXRoutput.WriteToFile( currOutFile + ".exr") #save the new EXR

This might cause a problem with elements with the same name. You will need to adjust for how your channels look.

Untested code BTW but I hope you get the idea.

J.

Thanks J… I was preparing a response that was very similar, but you beat me to it. A few things to note:

  • When referring to the channel names, you’ll want to use the unaltered ones, as those are the ones that the image is using. You can use the altered ones for the file names, assuming that’s how you’d like the images saved.
  • I would create a list that has the layer names (with r/g/b/a removed, plus duplicates removed of course), and then iterate through that list, reconstructing the channel names from the layer names… in case the layer names aren’t in the expected order. (I believe they should be, but it’s a bit more robust to not make that assumption.)
  • You might want to add in some conditions that handle whether or not there’s alpha channels.

Cheers,
Andrea

Thanks for the help! Im super new to python, but I’ll see what if I can make it work. Any gotcha’s or anything I should keep in mind?

I recommend using lots of debug print statements, to see that you’re getting what you think you’re getting. Mike has suggested I write this up as a tutorial/cookbook example, so if you’re struggling too much, let me know and I’ll move the priority of that item up, and post the code here as well. :wink:

Cheers,
Andrea

Oh man, that would be fantastic! We do some compositing in Nuke and some in After Effects. AE plays much better with the PNGs than EXRs, but I find it best to get as much info into our renders as possible. So if I could just run the script through Draft, that would make us all in the shop quite happy. When I say I’m super new to Python, I mean I’ve been doing tuts on it for less than a week. So the chances of me sorting this out in a timely fashion is rather slim I’m afraid :wink:

Thanks Andrea!

Would you mind attaching a sample EXR or two here, so that I know my example works with the “real thing”? :wink:

No problem at all! https://dl.dropboxusercontent.com/u/571676/sample_exrs.zip

There are two different EXR frame in the above link. They can get quite large, so I wont send the whole animation sequence. They are from two different test projects so they should give you an idea of the variation.

Let me know if you have any questions about them!

Thank you!

Perfect! Thanks! I’m just going to get something going, then I’ll work on that tutorial. (If I get pulled away, and haven’t responded back here in a reasonable time frame, feel free to poke me to remind me. :wink: )

Cheers,
Andrea

You’re welcome, this is all thanks to your and Jons help.

I forgot to rename the incoming channels to match the new outputs channels, Jon posted a sample of renaming channels earlier. Andreas suggestions are excellent.

J.

Andrea,

Something like a cookbook on getting started would be a great idea, I struggled to find information and had no idea what I was doing or where to look. I’m not even sure I’m going about things the right way now.

Thanks

Josh.

Yeah, I’ll probably end up with both a cookbook example and something for the sample scripts folder… the new cookbook example might not make it into the cookbook pages until we’ve switched them over to the new site, but I’ll get it posted here at a minimum for now.

Privacy | Site terms | Cookie preferences