Is it possible to apply chroma keying, meaning to remove a green (or blue…) screen background, using Gimp? (I happen to use Gimp, but I suppose an answer using Photoshop would be just as good, unless it’s referencing a specific Photoshop plugin.)
What I mean is the following:
(Note: I don’t know how to do it yet, this mockup was made starting from a stock transparent picture.)
If we look at what needs to be done (or approximated as far as possible, see below) it is the following:
Notice how this procedure is not merely adding an alpha channel; it is changing all colors that lie in the same quadrant as the key color itself. Meaning, if the key color is green, all greenish colors need to be substantially modified, in addition to having a suitable alpha channel added:
The reason I posted this question is that all other questions and answers about this topic miss this crucial point.
You can not turn a shade of green into semi-transparent red, and another shade of green into semi-transparent blue, just by fiddling with the magic wand, the color selection tool, or by copying a channel into a mask.
I don’t know the theoretical background behind chroma keying and I’m guessing it could be quite hairy. For instance, the color that lies exactly between the key color (green in this case) and its exact opposite (which would be magenta in this case) is a perfect gray (by definition of opposite color.) Do we need to turn that shade of gray into semi-transparent magenta? What if it was an actual gray in the original picture? (Which is actually more likely.)
Given all this undefined behaviour in the problem space itself, I’m sure Adobe Premiere and all the other professional video production tools contain very sophisticated chroma keying algorithms.
Can we even approximate the result of those algorithms using basic image manipulation, as found in Gimp? Or is any such endeavor bound to fail?
Alternatively, is there an open source Gimp plugin or separate program that can perform a good quality chroma keying on pictures?
Edit: Wikipedia’s article gives an example of a simple function for green screen:
rgb(r,g,b) -> rgba(r, min(g,b), b, A*(r+b)-B*g)and goes on to explain that modern algorithms can be much more complicated. Even with the simple function, I understand what it’s saying, but I would not know how to perform it using simple selections and channel manipulation.
Obviously your scalp with green background presents well your problematic images – large areas where the green is mixed with hair:
Unfortunately there’s no way to calculate exactly the original color of the mixes areas because we do not know is it mixed due the transparency (= more transparent hairs near the edges) or was it originally with no green background colored to more green at the edges than in the middle of the scalp. We must make a guess.
In your image of “what should be done” you guessed that the horizontal color stripes continue with the same hue and saturation, but the transparency increases as the color moves closer to pure green. Actually you didn’t guess, you constructed the stripes that way, but a dumb automate with no AI cleverness cannot know how an image is constructed. It sees only the mixing result pixel by pixel with no idea what kind of common creation process could be behind different pixels. You need something much more advanced than GIMP if you want some guessing ability.
To stay in truth your colored stripes would be recovered quite well with the next process because the programmer has thought in same way as you – like the unwanted color is there only due transparency.
The process: The green can be turned to transparency by applying Colors > Color to Alpha.
This is the result with your stripes:
The next one is a more realistic result – the background is mixed with the target in a complex way. It’s not pure linear transparency:
The treshold sliders are now quite randomly set. Areas which are pure green, only darker than the background are magenta. Areas which were too far from pure green, but still green are “as is”. The green vanishes but the red and blue increase if the opacity treshold slider is moved:
No good tresholds can be found. The other slider would crop the hair. But you can colorize the image. If your brain has some horsepower beyond the usual you can use channel mixer (Colors > Component > Channel Mixer). I skip it.
In your case a single hue recoloring can be acceptable. Pick from the original image a well saturated sample and fill with it a new top layer. Let that layer have blending mode Color LCH. There’s other “color” blending modes but Color LCH fits into this case because it it copies Hue and chroma from the sample:
merge the layers if the color is good.
You can desaturate the sparse areas like in the original by making a duplicate, desaturating the bottom copy and erasing with soft brush partially the colored top layer. Or preferably by inserting a layer mask for easy fix in case of errors.
Source : Link , Question Author : Tobia , Answer Author : user287001