Chroma key

Magick.NET is an object-oriented C# interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick.NET
Post Reply
dlinaresg
Posts: 6
Joined: 2013-02-20T16:37:00-07:00
Authentication code: 6789

Chroma key

Post 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
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Chroma key

Post 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
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
dlinaresg
Posts: 6
Joined: 2013-02-20T16:37:00-07:00
Authentication code: 6789

Re: Chroma key

Post by dlinaresg »

Thanks. Now testing...
Post Reply