##The Short Answer##

The effect of residual color is called a mate fringe. For example Photoshop has many tools to delete this most notably <kbd>**Layer &rarr; Matting &rarr; Defringe...**</kbd>. Other applications call this differently.

![Photoshop Layer -> Matting menu][1]

**Image 1**: Some of the fringe removal tools in Adobe Photoshop

##A Technical Description of the Problem##

Basically the idea is that a alpha mask can be mathematically described as:


&nbsp;&nbsp;&nbsp;   C<sub>out</sub> = &alpha; * C<sub>image</sub>  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(1)

Where C<sub>out</sub> is the out color and C<sub>image</sub> is the original color &alpha; is the alpha channel value. On pixels where 0 < &alpha; < 1 you have a pixel where the color is contaminated by both foreground an background color. If you happen to know the background color then you can derive from equation 1 that the contribution of the background is:

&nbsp;&nbsp;&nbsp;   C<sub>bg</sub> = (1 - &alpha;) * C<sub>known</sub>  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(2)

You can now proceed to delete that color from the foreground. You could simply subtract the color form the layer but you'd decontaminate the edge with black (which is what Photoshops remove black does). Removing black matte is simply,

&nbsp;&nbsp;&nbsp;   C<sub>unmult</sub> = C<sub>black</sub>/&alpha; ,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(3)

thus the total color of the pixel is:


&nbsp;&nbsp;&nbsp;   C<sub>final</sub> = (C<sub>image</sub> - (1 - &alpha;) * C<sub>known</sub>)/&alpha; **.**&nbsp;&nbsp;&nbsp;(4)

But what do you do if you dont know what the color is? Well you could make a guess as to the color by bleeding the non selected background into the subtraction plate C<sub>known</sub>, or bleed the foreground plate to alpha (this is what defringe does). There are fancier methods available.

  [1]: https://i.sstatic.net/MdkRB.png