Removing background from image with transparent foreground

0

I have an image which has a constant color background.  There are objects drawn in front which may have transparency. Is there a way, algorithm-wise, to remove the background from the image so that I should be left with an image with transparent objects with no background? I want to make this happen in my code so algorithm would be great.

gaurav

Posted 2015-07-25T00:09:41.260

Reputation: 13

Answers

0

If I understand the question correctly, and you don't have any extra information that you didn't tell us about, I believe that it's going to be impossible.  Consider the following composite image:

                blue rectangle with greenish circles

Obviously it has a blue background.  Now, here are the foreground objects:

                transparent yellow circle and opaque green circle

I don't see how you could possibly have an algorithm to get you the second image from the first — there isn't enough information to work with.


So, what can you do if you have more information?  What extra information would be useful?  Part of the answer is that you need to know where the foreground objects are.  If a foreground object is the same color as the background, or is 100% transparent, and it doesn’t have a border, it’s invisible, and there’s no algorithm that can even deduce its existence.  (And, if they overlap, it may help to know the stacking order.  It might be possible to deduce this (i.e., compute it by an algorithm), but I don’t know.)

But, given that you know where the objects are, consider: You have a background of color B, obscured by a foreground object of color F and transparency T.  What is the color (C) that you see?  C can be computed as a function of B, F, and T.  (If T=0, C=F; if T=1 (100%), C=B.)  You know B and C; it makes sense that you should be able to determine F or T if you know the other. 

There are exceptions, which I mentioned in the earlier paragraph.  If C=B, the object is invisible, because either it is the same color as the background (F=B) or it is 100% transparent (T=1).  If you know F=B=C, it is impossible to determine T.  If you know T=1, then it is impossible to determine F.  But at least in the second (T=1) case, if you just want to determine what the foreground object looks like: it looks white.

Many programs implement this function: PowerPoint (what I used to create my images), Photoshop, Paint.NET, GIMP, etc., and it’s probably documented.  I suggest that you research this function C=f(B,F,T) and figure out how to derive F=f′(B,T,C) and T=f″(B,F,C).

Scott

Posted 2015-07-25T00:09:41.260

Reputation: 17 653

that was my initial feeling. But the above picture made it clear. so what minimum extra information should i have to achieve what i want. – gaurav – 2015-07-25T09:19:07.317

After nearly 20 hours (more or less) of thinking about it (off and on), I believe I’ve figured out how to answer your second question and simultaneously give you some help with your primary question. – Scott – 2015-07-26T04:34:58.227

i think i found the function C = f(B,F,T) https://en.wikipedia.org/wiki/Alpha_compositing i will give this a try.

– gaurav – 2015-07-26T13:12:07.360