Page 1 of 1

Removing the Green Screen From the image

Posted: 2009-08-10T06:19:42-07:00
by varun
Hi ,
I just want to remove the green screen from the image taken with the green background , I want to generate a transparent image after tge green screen so that once I put this transparent image on any of the background , it should be a composite image with the new background.
Following is the example to see.
http://static.vsocial.com/vespa/images/ ... screen.jpg
In the above link you can see there is a scooter infront of a green screen. What I want to do is that I want to replace the green are with a transparent one. I all I want to generate a transparent image out of it .

Re: Removing the Green Screen From the image

Posted: 2009-08-10T08:18:53-07:00
by fmw42
I think you need to post a link to your file so that we can see what you have. I don't understand what you want to do.

Re: Removing the Green Screen From the image

Posted: 2009-08-10T10:16:48-07:00
by Bonzo
You do not say what method you are using but this will do what you want:

Code: Select all

convert GTS_yellow_green_screen.jpg -fuzz 20% -transparent #1eff01 output.png
There may be a slight green "halo" around the vespa - try increasing the -fuzz value to remove.

Try this to overlay it over your background image all in one line of code:

Code: Select all

convert GTS_yellow_green_screen.jpg -fuzz 20% -transparent #1eff01 miff:- | composite -compose Dst_Over background.jpg -
You will have a problem if the colour is in the vespa or what ever image you are using.

Here is a good tutorial about what you want to do:
http://tech.natemurray.com/2007/12/conv ... arent.html

This should not be in this section of the forum but the users section.

Re: Removing the Green Screen From the image

Posted: 2009-08-10T10:26:40-07:00
by el_supremo
Or with one convert command, (assuming that the green screen is pure green):

Code: Select all

convert green_test_bgnd.png ( green_test_ovl.png -alpha on -fuzz 20% -transparent rgb(0,255,0)  ) -composite green_test_out.png
Pete

Re: Removing the Green Screen From the image

Posted: 2009-08-10T21:23:37-07:00
by anthony
Technique for this problem is something I have been seriously considering for a very long time.

The obvious method as given above is simply to do a fuzzed color replacement. This works very well, but generates 'aliased' or thresholded edges. That however is find if you plan to save the image as a GIF image on transparency.

It also works very well on very very large images such as what you have provided, as after color replacement resizing the image smaller will restore the anti-aliasing (semi-transparent) edge pixels.

However this technique fails badly when the image is already small and will not be resized smaller! It is in these situations I have been trying to come up with ways of
recovering the original pixels before they were mixed with a known background color.

That is I am looking for way of subtracting a specific color leaving 1) the correct semi-transparency 2) the original color.

The technique Masking with Anti-Aliased Edges was developed with this goal in mind, but is only designed to recover the transparency, from wimages with a fixed color (usually black) border.

Re: Removing the Green Screen From the image

Posted: 2012-01-30T09:09:27-07:00
by cedk
Hi,

what about Green screen ?

Code: Select all

convert GTS_yellow_green_screen.jpg -channel alpha -fx "K0*b − K1*g + K2" output.png
CedK

Re: Removing the Green Screen From the image

Posted: 2012-01-31T21:03:21-07:00
by anthony
As someone decided to resurrect this very very old discussion.. New methods and techniques are now exampled in...

IM Examples, Photo Handling, Chroma-Key Masking
http://www.imagemagick.org/Usage/photos/#chroma_key
Which is essentially the same type of thing, but using hue for the actual masking.
The next section (incomplete)
http://www.imagemagick.org/Usage/photos/#green_screen
which includes a basic formula shown above for aliased pixel recovery.

The biggest addition however has been the working out of 'perfect background removal', but this is only possible if two different backgrounds are available (such as white and black) so this is not really 'green screen'
http://www.imagemagick.org/Usage/maskin ... background

Re: Removing the Green Screen From the image

Posted: 2012-02-01T02:05:26-07:00
by cedk
Looking on Google for solutions (my problem is to remove a blue screen in background), I found this topic, and solutions. I also saw that the subject had been consulted many times. Hence the decision for "someone" to bump the topic ...;-)
However, anyone know the formula for a blue background?

Someone (CedK)

Re: Removing the Green Screen From the image

Posted: 2012-02-01T05:31:17-07:00
by anthony
It is probably the same but with blue and green values swapped.

The formula comes from wikipedia, green screen. Their are other much more complex green screen anti-aliasing methods.

Once you have the 'alpha' and the known 'green screen' background, you can fix the colors as shown for the second step of 'perfect background removal'. It is the generation of the missing alpha that is the hard part, though the color fix formula was quite a puzzle for many years until solved by Forum Member HugoRune.

Re: Removing the Green Screen From the image

Posted: 2012-12-19T15:28:29-07:00
by lunawebs
we've got the concept of using GD to remove green from an image - how about removing from a video?
In other words a user uploads a video - we pull the frames from the video - edit them indivdiually - then render them out again to get a video with the chroma key work done.
Here's the catch - is it possible to go about this process without pulling out each individual frame?
How about now adding another video to the now newly rendered keyed out video?
You get the idea - you upload a video - the server / script keys out the green, takes the new video with the alpha channel and puts in an already produced video behind the subject.

Would love to hear any thoughts. Ideally - will use PHP on CentOS.

Re: Removing the Green Screen From the image

Posted: 2012-12-19T17:44:54-07:00
by fmw42
IM is an image processor and not a video processor. It will have to separate each frame and then put them back together again.

Re: Removing the Green Screen From the image

Posted: 2012-12-20T13:30:57-07:00
by lunawebs
thanks for the fast reply, we have ffmpeg splitting out the frames to images,
ffmpeg -i video.mov imagefolder/pic%d.png

working with image magick to pull the chroma key. It works but not great, we've tried
convert test.png -fuzz 20% -transparent #5db442 out.png

kind of blotchy, trying to figure out how to refine the edge

Re: Removing the Green Screen From the image

Posted: 2012-12-20T16:41:20-07:00
by fmw42