# How does OBS-Studio Chroma key work in real-time processing Alpha matting?



## JaredWei (Dec 5, 2018)

I am currently interested in the technology of Chroma key.
I like to play games myself.
Also played Youtube live,
But I have been wondering how the Mask (matte) of Chroma key is taken?
I used Mask to remove the background background in Photoshop, but how does it work in OBS-Studio?
It took me several months to find relevant technical information about Chroma key in the relevant websites of OBS-Studio. 
The place where the filter is introduced is not written in detail, and the source code of Open Source cannot be understood.
So I want to ask the developer of OBS-Studio, which is the Chroma key technology in the OBS-Studio filter?
Please let me know if there is a Chroma key technology page that you can refer to.

In addition, I have referenced the papers found on the Internet. 
I wonder if the Chroma key mentioned in the following link is the same technology?

High Quality Chroma Key
Hybrid key: An automatic tool for real-time high quality chroma keying

Thank you for taking the time to read, I look forward to your reply.
I wish you a happy life.


----------



## Jim (Dec 5, 2018)

It's just a pixel shader I wrote:  https://github.com/obsproject/obs-s...ins/obs-filters/data/chroma_key_filter.effect

The concept is pretty simple: convert the texture to YUV color space, then use the U and V channels to detect similar color to the target chroma key color (best is pure green or blue), then use that to create an alpha channel for the RGBA output.

I also do some stuff such as a simple box filter to smooth the edges of the alpha channel and make it look more nice and clean, but overall it's a pretty simple technique.


----------



## JaredWei (Dec 23, 2018)

Thanks Jim for the reply a few days ago!
Sorry, I have only recently returned.

I would also like to ask you, after these few days, I have studied the website and studied this rendering technology. Did he create a Mask that is a 2D plane?

Since the rendering method is used, the texture coordinates to be drawn are determined on the entire OBS preview screen, that is, the range to be drawn there, and then the character's Mask is drawn.

In other words, the distance between the pixel and the pixel is calculated by linear interpolation, and then the edge of the character is drawn by the linear difference distance, which is used to remove the edge of the character in time, so it is not used like Opencv. Too many algorithms to calculate his Mask are a bit like the way you paint on the canvas.

In the key color spill reduction processing, there is no feeling of rubbing the cloth on the canvas, so when the color spill parameter is raised to 1000, no matter what color background is used, the entire screen will be erased and the color will be grayed out. It is also called the loss of color.

I don't know if I have any understanding of the mistakes?

I don't know much about the rendering. I am completely new to DirectX, but I have a passion for the game.

The box filter is what I know. I can see it on the HLSL books that I can see now. It is a 3x3 average filter. Maybe I can switch to another filter to play with code.


Thank you for reading
Have a good day


----------



## cv_worker (Dec 31, 2019)

Jim said:


> It's just a pixel shader I wrote:  https://github.com/obsproject/obs-s...ins/obs-filters/data/chroma_key_filter.effect
> 
> The concept is pretty simple: convert the texture to YUV color space, then use the U and V channels to detect similar color to the target chroma key color (best is pure green or blue), then use that to create an alpha channel for the RGBA output.
> 
> I also do some stuff such as a simple box filter to smooth the edges of the alpha channel and make it look more nice and clean, but overall it's a pretty simple technique.


Excuse me.
What language does this shader use? Is openGL? or others? If it is openGL, what is the version of it?
Thank you!


----------

