This project has moved and is read-only. For the latest updates, please go here.

UsingColors Example

Jan 26, 2016 at 11:25 PM
Can anyone explain what the code is doing on this page:

I'm attempting to replace a green screen background with a transparent background, but this code doesn't seem to work. I added: image.Write(fileName); to my code and a new file is saved, but the background isn't removed.

I'm just looking for a quick and easy way to remove a green screen background.

Jan 27, 2016 at 9:19 AM
That page just demonstrates the various constructors. I am not sure how you could remove the green screen background. Maybe the following stack-overflow post will be able to help you:
Jan 27, 2016 at 8:54 PM
Thanks for the reference, but I'm looking for c# code to do this.
Jan 27, 2016 at 8:57 PM
I might be able to help you if you add a link to your input image.
Jan 27, 2016 at 8:59 PM
Here is a sample that I've been using:
Jan 30, 2016 at 6:26 PM
I converted the example from the reference to C# but I am unable to get the result you would like. Here is my code so far:
using (MagickImage image = new MagickImage("maxresdefault.jpg"))
  image.ColorSpace = ColorSpace.HSV;
  var channels = image.Separate().ToArray();

  channels[0].BackgroundColor = MagickColors.Transparent;
  channels[0].ColorFuzz = new Percentage(5);
  channels[0].InverseTransparent(new MagickColor("grey32"));

  channels[1].BackgroundColor = MagickColors.Transparent;
  channels[1].ColorFuzz = new Percentage(10);
  channels[1].Transparent(new MagickColor("grey50"));

  channels[2].BackgroundColor = MagickColors.Transparent;
  channels[2].ColorFuzz = new Percentage(20);
  channels[2].Transparent(new MagickColor("grey60"));

  channels[0].Composite(channels[1], CompositeOperator.Multiply);
  channels[0].Composite(channels[2], CompositeOperator.Multiply);


  image.Composite(channels[0], CompositeOperator.CopyAlpha);

I think you will need to tweak the percentages/gray colors to get the result that you want.