Page 1 of 1

Chroma key

Posted: 2018-02-16T07:09:03-07:00
by dlinaresg
Hi.I have the idea to implement any kind of Chroma key just like here: http://www.imagemagick.org/Usage/photos/#chroma_key, but using magick.net.

convert shirt.jpg -modulate 100,100,33.3 -colorspace HSL \
-channel Hue,Saturation -separate +channel \
\( -clone 0 -background none -fuzz 5% +transparent grey64 \) \
\( -clone 1 -background none -fuzz 10% -transparent black \) \
-delete 0,1 -alpha extract -compose multiply -composite \
shirt_mask.png

First three steps I think are easy:
image6.Modulate(new Percentage(100), new Percentage(100), new Percentage(33.3));
image6.ColorSpace = ColorSpace.HSL;
image6.Separate();

But cannot understand how to implement separate and clone steps.

Thanks

Re: Chroma key

Posted: 2018-02-18T10:16:58-07:00
by dlemstra
Your command would translate to this:

Code: Select all

// convert shirt.jpg
using (var shirt = new MagickImage("shirt.jpg"))
{
    // -modulate 100,100,33.3
    shirt.Modulate(new Percentage(100), new Percentage(100), new Percentage(33.3));

    // -colorspace HSL
    shirt.ColorSpace = ColorSpace.HSL;

    // -channel Hue,Saturation -separate +channel
    using (MagickImageCollection images = new MagickImageCollection(shirt.Separate(Channels.Red | Channels.Green)))
    {
        // No need to clone because we can work on the original images.
        // -delete 0,1 deletes them

        // -background none
        images[0].BackgroundColor = MagickColors.None;

        // -fuzz 5%
        images[0].ColorFuzz = new Percentage(5);

        // +transparent grey64
        images[0].InverseTransparent(new MagickColor("grey64"));

        // -background none
        images[1].BackgroundColor = MagickColors.None;

        // -fuzz 10%
        images[1].ColorFuzz = new Percentage(10);

        // -transparent black
        images[1].Transparent(new MagickColor("black"));

        // -alpha extract
        images[0].Alpha(AlphaOption.Extract);
        images[1].Alpha(AlphaOption.Extract);

        // -compose multiply - composite
        images[0].Composite(images[1], CompositeOperator.Multiply);

        clone0.Write("shirt_mask.png");
    }
}
g

Re: Chroma key

Posted: 2018-02-19T10:20:11-07:00
by dlinaresg
Thanks. Now testing...