Green color color screen using ImageMagick

I was looking for a good algorithm for a green color screen using ImageMagick, but have not yet received a satisfactory answer.

I would like to learn a simple method of using range selection by HSV / HSB color space (similar to -fuzz) to select the green color that I want and make it transparent. It seems that -fuzz only applies in RGB space, which is undesirable.

Can someone teach me how to choose a color with a separate range for the component H, S, V, for example, 115-125 degrees of hue, 40% -60% Saturation and 30-80%.

If there is another best color key algorithm, your advice is also much appreciated.

Thanks in advance.

+5
source share
1 answer

Imagemagick FX -. hue, saturation, lightness luma, value max (r, g, b).

hueMin=115/360;
hueMax=125/360;
saturationMin=0.40;
saturationMax=0.60;
valueMin=0.30;
valueMax=0.80;
value = max( r, max( g, b ) );
(
  ( hue > hueMin && hue < hueMax ) && (
  ( saturation > saturationMin && saturation < saturationMax ) || 
  ( value > valueMin && value < valueMax ))) ? 0.0 : 1.0

hsl-greenscreen.fx

convert source.png -channel alpha -fx @hsl-greenscreen.fx out.png

FX script, , . , , .

- -fuzz, HSV. , -fuzz .

convert source.png -colorspace HSV -separate +channel \
  \( -clone 0 -background none -fuzz 5% +transparent grey32 \) \
  \( -clone 1 -background none -fuzz 10% -transparent grey50 \) \
  \( -clone 2 -background none -fuzz 20% -transparent grey60 \) \
  -delete 0,1,2 -alpha extract -compose Multiply -composite \
  -negate mask.png

-

convert source.png mask.png -alpha Off -compose CopyOpacity -composite out.png
+3

All Articles