chroma key from two pictures: help needed

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
nitrofurano
Posts: 8
Joined: 2011-02-13T07:37:10-07:00
Authentication code: 8675308

chroma key from two pictures: help needed

Post by nitrofurano »

Do someone know how can we do chroma key on imagemagick?
This would be like generate a third picture, from two source pictures (one as background, and another for the above 'layer' using blue or green as transparent colour )
http://en.wikipedia.org/wiki/Chroma_key explains a bit better what it is, for people don't know what is it about
My idea were using this with a picture sequence generated from ffmpeg, from a script
Any feedback of a command-line for this is very welcome, or developers please consider adding this feature if missing
Thanks!

User avatar
fmw42
Posts: 26094
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: chroma key from two pictures: help needed

Post by fmw42 »

If you can provide two simple images that you want to merge, we can likely help.

Assuming one image has a lot of blue in it, then something like

convert backgroundimage \( foregroundblueimage -fuzz XX% -transparent blue \) -compose over -composite resultimage

where XX is some number between 0 and 100 that controls how close any color is to blue that will be made transparent (0 means exactly the color blue).

See
http://www.imagemagick.org/Usage/color_basics/#replace
http://www.imagemagick.org/Usage/compose/#compose

User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: chroma key from two pictures: help needed

Post by anthony »

Hmmm idea. As the color trying to be turned into a mask is a specific color, rather than a dedicated channel, perhaps we can use a Hue color space to generate the mask needed.

That is convert both the reference color and actual image to HSL color space and then convert the reference color to transparency. The Hue channel image can then be used to generate the mask.

That should allow us to 'notch' that specific color a little more definitely, rather than trying to do so in RGB space as we have attempted to do in the past.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/

Post Reply