# PIK node¶

This documentation is for version 1.0 of PIK (net.sf.openfx.PIK).

## Description¶

A keyer that works by generating a clean plate from the green/blue screen sequences. Inspired by Nuke’s IBK by Paul Lambert and Fusion’s KAK by Pieter Van Houte.

There are 2 options to pull a key with PIK. One is to use PIKColor to automatically extract a clean plate from the foreground image and use it as the the C input, and the other is to pick a color which best represents the area you are trying to key.

The blue- or greenscreen image should be used as the Fg input, which is used to compute the output color. If that image contains significant noise, a denoised version should be used as the PFg input, which is used to pull the key. The C input should either be a clean plate or the output of PIKColor, and is used as the screen color if the ‘Screen Type’ is not ‘Pick’. The Bg image is used in calculating fine edge detail when either ‘Use Bg Luminance’ or ‘Use Bg Chroma’ is checked. Optionally, an inside mask (a.k.a. holdout matte or core matte) and an outside mask (a.k.a. garbage matte) can be connected to inputs InM and OutM. Note that the outside mask takes precedence over the inside mask.

If PIKcolor is used to build the clean plate, the PIKColor Source input should be the same as the PFg input to PIK, e.g. the denoised footage, and the inside mask of PIK can also be fed into the InM input of PIKColor.

The color weights deal with the hardness of the matte. When viewing the output (with screen subtraction checked), one may notice areas where edges have a slight discoloration due to the background not being fully removed from the original plate. This is not spill but a result of the matte being too strong. Lowering one of the weights will correct that particular edge. For example, if it is a red foreground image with an edge problem, lower the red weight. This may affect other edges so the use of multiple PIKs with different weights, split with KeyMixes, is recommended.

The Alpha Bias setting may be used either if there is a strong global color cast on the scene (e.g. the green or blue screen color is not pure), or if parts of the foreground are transparent in the output. This color is considered by the algorithm as being a grey reference: all colors from the PFg input are first normalized by this color before computation.

If the Alpha Bias is set, but the screen subtraction has a strong color bias (e.g. the despilled areas show the screen color), uncheck ‘Use Alpha for Despill’ and set the Despill Bias to the color of the foreground elements that are most affected by the color bias.

‘Screen Subtraction’ (a.k.a. despill) removes the background color from the output via a subtraction process (1-alpha times the screen color is subtracted at each pixel). When unchecked, the output is simply the original Fg premultiplied with the generated matte.

‘Use Bkg Luminance’ and ‘Use Bkg Chroma’ affect the output color by the new background. This feature can also sometimes really help with screens that exhibit some form of fringing artifact - usually a darkening or lightening of an edge on one of the color channels on the screen. The effect can be offset by grading the Bg input up or down with a grade node just before input. If it is just an area which needs help then just rotoscope that area and locally grade the Bg input up or down to remove the artifact.

The output of PIK is controlled by the “Output Mode” option. For example, if the output is “Premultiplied”, it should be composited with the background using a Merge-over operation.

The basic equation used to extract the key in PIK is (in the case of “green” keying):

alpha = 0 if (Ag-Ar*rw-Ab*gbw) is negative, else 1-(Ag-Ar*rw-Ab*gbw)/(Bg-Br*rw-Bb*gbw)

A is input PFg and B is input C, rw is the value of “Red Weight” and gbw is the value of “Green/Blue Weight”.

## Inputs¶

Input Description Optional
Fg The blue- or greenscreen image. Used to compute the output color. No
PFg (optional) The preprocessed/denoised blue- or greenscreen image. Used to compute the output key (alpha). A denoised image usually gives a less noisy key. If not connected, the Fg input is used instead. Yes
C (optional) A clean plate if available, or the output of PIKColor to generate the clean plate at each frame. Yes
Bg (optional) The background image. This is used in calculating fine edge detail when the ‘Use Bg Luminance’ or ‘Use Bg Chroma’ options are checked. Yes

## Controls¶

Parameter / script name Type Default Function
Screen Type / screenType Choice C-Blue
The type of background screen used for the key.
C-Green (green): Background screen with a green tint.
C-Blue (blue): Background screen with a blue tint.
Pick (pick): The background screen color is selected by the “color” parameter, and the type of screen (green or blue) is set automatically from this color.
Color / color Color r: 0 g: 0 b: 1 The screen color in case ‘Pick’ was chosen as the ‘Screen Type’.
No Key / noKey Boolean Off Apply despill, background luminance and chroma to Fg rgba input using the Fg alpha channel as the key - no key is pulled, but Inside Mask and Outside Mask are applied if connected.
Red Weight / redWeight Double 0.5 Determines how the red channel and complement channel (blue for a green screen, green for a blue screen) are weighted in the keying calculation.
Blue/Green Weight / blueGreenWeight Double 0.5 Determines how the red channel and complement channel (blue for a green screen, green for a blue screen) are weighted in the keying calculation.
Alpha Bias / alphaBias Color r: 0.5 g: 0.5 b: 0.5 Divide C and PFg colors by this color before computing alpha. This may be used when the whole scene, including the background, has a strong color cast.
Despill Bias / despillBias Color r: 0.5 g: 0.5 b: 0.5 Divide C color by this color before despill.
Use Alpha Bias for Despill / despillBiasIsAlphaBias Boolean On Use alpha bias color for despill instead of despill bias color.
Screen Subtraction / ss Boolean On Have the keyer subtract the foreground or just premult.
Clamp / clampAlpha Boolean On Clamp matte to 0-1.
Clip Black / screenClipMin Double 0 Any alpha below this value is set to 0.
Clip White / screenClipMax Double 1 Any alpha above this value is set to 1.
Screen Replace / screenReplace Choice Soft Color
What to do with the color of the pixels for which alpha was modified by the screen matte settings.
None (none): Subtracted image is not affected by alpha modifications.
Source (source): When alpha is modified, a corresponding amount of the Fg color is added.
Hard Color (hardcolor): When alpha is modified, a corresponding amount of the replace color is added.
Soft Color (softcolor): When alpha is modified, a corresponding amount of the replace color is added, but the resulting luminance is matched with Fg.
Screen Replace Color / screenReplaceColor Color r: 0.5 g: 0.5 b: 0.5 The color to use when the Screen Replace parameter is set to Soft or Hard Color.
Source Alpha / sourceAlphaHandling Choice Ignore
How the alpha embedded in the Source input should be used
Ignore (ignore): Ignore the source alpha.
Inside Replace / insideReplace Choice Soft Color
What to do with the color of the pixels for which alpha was modified by the inside mask.
None (none): Subtracted image is not affected by alpha modifications.
Source (source): When alpha is modified, a corresponding amount of the Fg color is added.
Hard Color (hardcolor): When alpha is modified, a corresponding amount of the replace color is added.
Soft Color (softcolor): When alpha is modified, a corresponding amount of the replace color is added, but the resulting luminance is matched with Fg.
Inside Replace Color / insideReplaceColor Color r: 0.5 g: 0.5 b: 0.5 The color to use when the Inside Replace parameter is set to Soft or Hard Color.
Use Bg Luminance / ubl Boolean Off Have the output RGB be biased by the difference between the Bg luminance and the C luminance). Luminance is computed using the given Colorspace.
Use Bg Chroma / ubc Boolean Off Have the output RGB be biased by the Bg chroma. Chroma is computed using the given Colorspace
Colorspace / colorspace Choice Rec. 709
Formula used to compute luminance and chrominance from RGB values for the “Use Bg Luminance” and “Use Bg Choma” options.
Rec. 709 (rec709): Use Rec. 709 with D65 illuminant.
Rec. 2020 (rec2020): Use Rec. 2020 with D65 illuminant.
ACES AP0 (acesap0): Use ACES AP0 with ACES (approx. D60) illuminant.
ACES AP1 (acesap1): Use ACES AP1 with ACES (approx. D60) illuminant.
Output Mode / show Choice Premultiplied
What image to output.
Source (source): The PFg input (or Fg input, if PFg is not connected).
Source Alpha (sourcealpha): The Alpha channel from the PFg input (or Fg input, if PFg is not connected), displayed as luminance.
Clean Plate (cleanplate): The clean plate from the C input (or the screen color, if C is not connected).
Screen Matte (screenmatte): The screen matte after keying and screen matte processing, but before applying the inside and outside mask, displayed as luminance.