views:

164

answers:

3

I'm looking for a way to automatically remove (=make transparent) a "green screen" portrait background from a lot of pictures.

My own attempts this far have been... ehum... less successful.

I'm looking around for any hints or solutions or papers on the subject. Commercial solutions are just fine, too.

And before you comment and say that it is impossible to do this automatically: no it isn't. There actually exists a company which offers exactly this service, and if I fail to come up with a different solution we're going to use them. The problem is that they guard their algorithm with their lives, and therefore won't sell/license their software. Instead we have to FTP all pictures to them where the processing is done and then we FTP the result back home. (And no, they don't have an underpaid staff hidden away in the Philippines which handles this manually, since we're talking several thousand pictures a day...) However, this approach limits its usefulness for several reasons. So I'd really like a solution where this could be done instantly while being offline from the internet.

EDIT: My "portraits" depictures persons, which do have hair - which is a really tricky part since the green background will bleed into hair. Another tricky part is if it is possible to distingush between the green in the background and the same green in peoples clothes. The company I'm talking about above claims that they can do it by figuring out if the green area are in focus (being sharp vs blurred).

+1  A: 

PaintShop Pro allows you to remove backgrounds based on picking a color. They also have a Remove Background wand that will remove whatever you touch (converting those pixels to transparent). You can tweak the "tolerance" for the wand, such that it takes out pixels that are similar to the ones you are touching. This has worked pretty well for me in the past.

To automate it, you'd program a script in PSP that does what you want and then call it from your program. This might be a kludgy way to to do automatic replacement, but it would be the cheapest, fastest solution without having to write a bunch of C#/C++ imaging code or pay a commercial agency.

They being said, you pay for what you get.

sohtimsso1970
I believe he's looking for an automated "server-side" solution.
k00k
First I said *automatically*. And this cannot possibly solve the problem with the green color being reflected and shining through (especially blonde) hair. That requires quite a bit of manual work. And how many peoble would it take to do this to 5000 images a day...?
danbystrom
PSP can be automated. It might be kludgy but you can write scripts that run by command.
sohtimsso1970
You've mentioned the hair issue several times (here and in an answer below). That is why I suggested programming against a commercial product like PSP. It already contains algorithms to figure out what pixels are "similar shades of green" and which are not. You don't want to try and do that stuff yourself. Find a commercial product (like PSP) that offers scripting and shell it open.
sohtimsso1970
@sohtimsso1970, upvoted since I think the downvote was unfair, regardless of the source. I misunderstood the question so it's likely that lesser mortals may have as well :-) You may want to consider deleting the answer while you're ahead if you agree it doesn't match the question.
paxdiablo
+2  A: 

Take a look at this thread: http://www.wizards-toolkit.org/discourse-server/viewtopic.php?f=2&t=14394&start=0

and the link within it to the tutorial at: http://tech.natemurray.com/2007/12/convert-white-to-transparent.html

Then it's just a matter of writing some scripts to look through the directory full of images. Pretty simple.

k00k
I should note, I've not tried this, and YMMV. Especially when it comes to anti-aliasing and soft edges.
k00k
This will take me quite a bit of time to wade through, but this seems to be exactly the sort of stuff I'm trying to pick up! Although I seriously doubt the "Pretty simple" part! :-)
danbystrom
Heh, I meant that the scripting part is the easy part. :)
k00k
+2  A: 

If you know the "green color" you may write a small program in opencv C/C++/Python to do extract that color and replace with transparent pixels.

rics
I can find the green color by inspecting the areas which I know should contain mostly green and calculating the median value... but the problem is hair, hair, hair... the green color bleeds into the hair and mixes with it... and then we have the problem with clothes in the same green color...
danbystrom
Based on your description above, my answer is correct. Based on you comment it is not. But why should I know it in advance to merit the downvote?Happy searching.
rics
Yes, I think that too. I wasn't the one who downvoted you. I consider your answer fully valid (although not appicable - as noted).
danbystrom
@rics, upvoted since I think the downvote was unfair, regardless of the source. I misunderstood the question so it's likely that lesser mortals may have as well :-) You may want to consider deleting the answer while you're ahead if you agree it doesn't match the question.
paxdiablo