Home Creators Posts Import Register Favorites Logout

Content

One of the most important and powerful tools in Gaffer is the Wedge node. Wedge lets us automate the creation of many versions of any scene.

Let’s take a look, plus learn some advanced Python scripting along the way!

We’ll use an image processing workflow for these examples but the same principles can be applied to anything else that Gaffer can do.

The key parameters in a Wedge are Variable, Index Variable and Mode.

Variable sets which Context Variable the Wedge modifies.

Index Variable produces a counter so we know which iteration of the Wedge we’re on.

Mode sets the Variable’s type and contents.

Import an image with an ImageReader pointing to an image of your choice. Connect an ImageWriter, two Wedges and a LocalDispatcher.

We’ll use the first Wedge to automate the creation of multiple grades of our input image. Set the Variable to gain, the Index Variable to masterIndex and the Mode to Color Range with 4 steps.

Note that, while not strictly necessary, it’s a good idea to “declare” Context Variables in the File > Settings > Variables menu.

If you don’t, you’ll get a lot of errors complaining about unknown variables. The Wedges and Dispatch will work without this step, but navigating the scene is a pain if you don’t do it.

Insert a Grade node above.

Right click on the Gain parameter and select Create Python Expression…

In the code editor, paste the following:

parent["Grade"]["gain"] = context["gain"]

This tells Gaffer to set the Grade node’s Gain parameter to the value of the gain Context Variable that our Wedge modifies. When we run our Dispatcher the Wedge will loop four times over the scene with a different gain value each time.

Next, we’ll use the second Wedge to create several different size outputs. Set the values as follows:

Then, insert an ImageTransform and a Crop above.

Create a new Python Expression for the ImageTransform’s Scale parameter and paste the following:

import imath

parent["ImageTransform"]["transform"]["scale"] = imath.V2f(context["scale"])

We use the Imath library to create a vector input for the Scale parameter (two float values, both of which are our Wedge’s scale Context Variable).

This Wedge will also loop four times, resizing the image to the values we set.

Finally, let’s get a little fancy just because we can and set custom image output names based on the state of our various Context Variables.

Attach a Python Expression to the ImageWriter’s File Name parameter and set it up as follows (with paths appropriate for your system):

scaleNames = ["tiny", "small", "medium", "large"]

parent["ImageWriter"]["fileName"] = f'C:/Users/Brian/Desktop/output/butterfly.{context["masterIndex"]}.{scaleNames[context["scaleIndex"]]}.png'

Here we fetch our masterIndex and our scaleIndex counters and use them to customize the filename for each output image. We created a string array with names for each image size and then fetch the name using the scaleIndex as it loops (scaleNames[0] = “tiny,” 1 = “small,” etc.).

Click Dispatch in the LocalDispatcher and there you go: graded, resized and named images all produced with the press of button!

Files

Comments

No comments found for this post.