[Bf-committers] Inpaint node review

Peter Schlaile peter at schlaile.de
Sun Jul 15 22:58:49 CEST 2012


I wrote an inpaint node for the compositor.

Since we are directly before a release, I haven't commited it, but I'd
like people to review it.

In case, you don't know, inpainting does this:

It's use cases in blender are 

* wire removal
* green screen background reconstruction

the later is important to actually improve keying in blender. (see

The node isn't tile based (for fundamental reasons), but very fast,
since it first builds a manhatten distance map and after that performs
color convolution only on the edges.

That's something, one should probably add also to the dilate node (in
step mode) to make it perform a lot better for dilate iterations greater
than 3.

It will bring it's computing time from O(n^3) down to O(n^2).
Take a look here for the details: 
http://ostermiller.org/dilate_and_erode.html )

My aim is implementing something like the IBK Keyer in Nuke
(http://www.youtube.com/watch?v=-GmMC0AYXJ4 ), since all current
solutions within Blender fail on hair details rather badly.

You can see first steps in this direction here, which already do some
nice improvements:

(compare key_raw.png to inpaint_key.png )

The trick I use is the following:

If you consider the usual compositing equation

Composite = Background * (1-ALPHA) + Foreground * ALPHA

for the case, that Background is our GreenScreen and Foreground is the
Object, we want to seperate, you'll notice, that we more or less
successfully can pull an alpha-matte (using a color channel node), but
currently fail to subtract the GreenScreen Background properly from the

That's no surprise, since until now, the GreenScreen Background wasn't
actually known (we don't have any clean plates shot in Mango).

But: we can inpaint the surrounding greenscreen into the area *behind*
the semi-transparent regions and subtract that instead. 

The only thing missing in blender for that task, is said inpainting
node. And that's why I added it :)

So: please use my git repository at


git checkout image-keyer

and tell me your findings.

If I should commit to trunk, please let me know. If team Mango can make
use of it, feel free to commit to tomato branch.

Cheers and good night,

P.S.: There are a lot more sophisticated solutions for inpainting, some
are convolution based, like my simple approach (which convolves the
known surrounding pixels with a weighted average into the unknown
region), some are a lot more advanced. For all practical reasons (the
ones noted above), my node should work fairly well. If you want to add
additional inpainting algos, feel free to add a type and activate
custom1 as a type parameter variable.

Peter Schlaile

More information about the Bf-committers mailing list