.. index:: Compositor Nodes; Keying
.. _bpy.types.CompositorNodeKeying:

***********
Keying Node
***********

.. figure:: /images/node-types_CompositorNodeKeying.webp
   :align: right
   :alt: Keying Node.

The *Keying* node is a one-stop-shop for "green screen" / "blue screen" removal.
It performs both chroma keying to remove the backdrop and despill to correct color cast from the backdrop.
Additionally, you can perform common operations used to tweak the resulting matte.


Inputs
======

Image
   Standard color input.
Key Color
   The color of content to be removed. This may be a single color,
   or a reference image such as generated by
   the :doc:`Keying Screen Node </compositing/types/keying/keying_screen>`.


Preprocess
----------

Blur Size
   Reduce the effects of color noise in the image by blurring only color by the given amount,
   leaving luminosity intact. This will affect matte calculation only, not the result image.


Key
---

Balance
   This is the balance between color channels compared with the key color.
   0.5 will average the other channels (red and blue in the case of a green screen).

   This may be tweaked in tandem with *Clip Black* and *Clip White* while
   checking the *Matte* output to create a mask with optimal separation.


Tweak
-----

Black Level
   This sets the threshold for what becomes fully transparent in the output (black in the matte).
   It should be set as low as possible. Uneven backdrops will require this value to be increased.
   Use of the :doc:`Keying Screen Node </compositing/types/keying/keying_screen>` can help
   keep this value low. You may also use a *Garbage Matte* to exclude problematic areas.

   This value does not impact areas detected as edges to ensure edge detail is preserved.
White Level
   This sets the threshold for what becomes fully opaque in the output (white in the matte).
   It should be set as high as possible. Colors close to green in the foreground
   may require reducing this value and/or adjusting the *Screen Balance*.
   Particularly problematic parts can fixed with a *Core Matte* instead of a low *Clip White*.

   This value does not impact areas detected as edges to ensure edge detail is preserved.


Edges
^^^^^

Size
   Defines the radius in pixel used to detect an edge.
Tolerance
   Defines threshold used to check if pixels in radius are the same as current pixel:
   if the difference between pixel colors is higher than this threshold then the point
   will be considered an edge.

.. tip::

   If there are problems with the edges of the matte, it may help to start with
   adjusting the *Edge Kernel* parameters before adjusting feathering.
   Detected edges are not subject to *Clip Black* / *Clip White* thresholds
   to preserve fine edge detail. You can check edge detection by connecting
   a :doc:`Viewer Node </compositing/types/output/viewer>` to the *Edges* output.

   Sharper detected edges (smaller *Size*, like 2 / larger *Tolerance*, like 0.4)
   will create a sharper matte, but may loose some detail like stray hairs.
   A sharp matte is good, but disappearing or flickering hairs are distracting.

   Fat edges (larger *Size*, like 8 / smaller *Tolerance*, like 0.05)
   will capture more edge detail, but may also produce a halo around the subject.
   The halo can be adjusted with *Feather* controls along with *Dilate/Erode*.


Mask
----

Garbage Matte
   An optional mask of area(s) to always *exclude* from the output.
   This is removed from the chroma key generated matte.
Core Matte
   An optional mask of area(s) to always *include* in the output.
   This is merged with the chroma key generated matte.


Postprocess
-----------

Blur Size
   Make the matte less sharp, for smoother transitions to the background and noise reduction.
Dilate Size
   Enlarge (positive numbers) or shrink (negative numbers) the matte by the specified number of pixels.
   This is similar to using the :doc:`Dilate/Erode Node </compositing/types/filter/dilate_erode>` on the matte.

   This a simple way to include more or less along the edges of the matte, particularly combined with *Post Blur*.
Feather Size
   Controls how much the matte is feathered inwards (negative number) or outwards (positive number).
Feather Falloff
   The rate of the falloff at the edges of the matte when feathering, to manage edge detail.


Despill
-------

Strength
   Controls how much color bleed from the key color is removed from the input
   image: 0 means no despilling, 1 means all possible spilling will be removed.
   The underlying implementation is the same as adjusting the *Unspill* amount
   of the :doc:`Color Spill Node </compositing/types/keying/color_spill>`.
Balance
   This controls how the color channels are compared when computing spill,
   affecting the hue and shade of the corrected colors.
   It is similar to setting the *Limiting Channel*
   in the :doc:`Color Spill Node </compositing/types/keying/color_spill>`.


Outputs
=======

Image
   Processed image with the *Matte* applied to the images' :term:`Alpha Channel`.
Matte
   Output matte to use for checking the quality of the key, or to manually apply
   using a :doc:`Set Alpha Node </compositing/types/color/set_alpha>` or
   :doc:`Mix Node </compositing/types/color/mix_color>`.
Edges
   Shows what edges were detected on the matte.
   Useful for adjusting the *Edge* *Size* and *Tolerance*.
