

Var bytes = Math.Abs(data.Stride) * clone.Height

Var data = clone.LockBits(new Rectangle(0, 0, clone.Width, clone.Height), ImageLockMode.ReadWrite, clone.PixelFormat) Gr.DrawImage(input, new Rectangle(0, 0, clone.Width, clone.Height)) Using (Graphics gr = Graphics.FromImage(clone)) That project takes a folder and process all files, I just need an image so I did this: private Bitmap RemoveBackground(Bitmap input)īitmap clone = new Bitmap(input.Width, input.Height, PixelFormat.Format32bppArgb) I looked for a different solution and I found a project that uses a more efficient method here. I've tried Mario solution and it worked perfectly but it's a bit slow for me. You can also add smoothening between frames, blending (where there's less green difference), etc. Just note that you might need different thresholds ( 8 and 96 in my code above), you might even want to use a different term to determine whether some pixel should be replaced. I've used an example image from Wikipedia and got the following result: Iterate over all piels from top to bottom.įor (int y = 0 y 96 // minimum difference between smallest/biggest value (avoid grays) Bitmap input = new output = new Bitmap(input.Width, input.Height) Just note that this isn't necessarily the most performant way to do this.
CHANGE GREEN SCREEN BACKGROUND IMAGES PORTABLE
While I used Windows Forms, it should be portable without problems and I'm pretty sure you'll be able to interpret the code. This will give you a better color average.
CHANGE GREEN SCREEN BACKGROUND IMAGES PRO
Pro tip: Hold CTRL while you click the green screen color to sample even more pixels. For Screen Color, select the Color Picker and click on an area of the green screen close to your subject. I've toyed around a bit using some simple sample code. Let’s start with the Keylight effect, which we’ll use the select the green screen background. While this would work with very basic scenes, it can screw you up (e.g. The most basic formula would involve something as simple as "determine whether green is the biggest value". The basics are simple: Compare the image pixel's color with some reference value or apply some other formula to determine whether it should be transparent/replaced. Since at least some links on your linked page are dead, I tried my own approach: It will work, even if the background isn't uniform, you'll just need the proper strategy that is generous enough to grab all of your greenscreen without replacing anything else.
