# Blending Edges in photoshop to a different color of an extracted object with different background color

What are some awesome ways to blend anti aliased edges of an object that has been extracted, lets say from dark background, or any light/dark unique color. And needs to be placed on different most likely on opposite color. Like object taken from black on white.

-Removing all pixels doesnt help. It makes it look extra crispy.

-Feathering is visible.

I wish i could find a way where values of edges is extracted and then blended with the new background. Or Basically i am asking how to make edges anti-aliased pixels transparent when extracting an object in photoshop.

• Any chance you could provide a screenshot of what you've attempted? – JohnB May 24 '13 at 0:57
• this is not a specific problem question...this is something that comes every now and then. I have tried lots of things. Take any photo crop it and you will see that its anti aliased edges have blending from previous color so is there a way that you know of making them blend to another color, perhaps by being transparent. – user8795 May 24 '13 at 3:44
• @MuhammadUmer Depending how how you crop them, you will have those edges. But using a mask and fading them a little should be enough to remove them. – Yisela May 24 '13 at 4:26
• yes in some situation that's enough but that is not what i am asking i am asking to extract value/brightness + transparency of edges and not hue itself. – user8795 Nov 7 '13 at 20:22

You can't make a transparent image adapt to all backgrounds backgrounds, at least not in the way you mention. No matter what color you have behind it, the transparent image itself will always be the same.

You might have noticed that some gif files look better on light OR dark backgrounds, they have like an added border. This border is added to the image when it's saved, and it's not dynamic (it's called Matte, and you can see it if you "Save for Web" as gif in Photoshop - an icon with dark matte will look better in dark backgrounds, but terrible in light ones).

The best way to remove the background of an image, and have a smooth effect so there are no traces of any other colors in your transparent element is probably to use Masks. Masks are easy to re-adjust, and the borders are not as 'edgy'. Unfortunately, not all colors looks the same in light/dark backgrounds. Sometimes the colors will just look terrible together, like red on top of blue...

• thanks for useful answer...but there should be something. I mean we know color of the edge and the background and color of blending in between. Let see – user8795 May 24 '13 at 3:46

The effect of residual color is called a mate fringe. For example Photoshop has many tools to delete this most notably Layer → Matting → Defringe.... Other applications call this differently, but they all quite universally have tools for this.

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:

Cout = α * Cimage                                   (1)

Where Cout is the out color and Cimage is the original color α is the alpha channel value. On pixels where 0 < α < 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:

Cbg = (1 - α) * Cknown                            (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,

Cunmult = Cblack/α ,                                (3)

thus the total color of the pixel is:

Cfinal = (Cimage - (1 - α) * Cknown)/α .   (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 Cknown, or bleed the foreground plate to alpha (this is what defringe does). There are fancier methods available.

### Related explanations:

Can image transparency be calculated automatically from multiple non-transparent samples?, where I describe step by step how the subtraction could be done in a slightly more involved example.

• after some thought the conclusion: basically alpha value needs to be extracted out from color. For which one needs to know 2 out of 3 things:foreground color, alpha value and background color. And in case where we don't know background color or its multiple/complex and neither alpha value is known then we use black or white as background. Which leaves us with bg color & fg color. From which we should be able to calculate alpha. new color would be fg color * alpha. Am i at right path? – user8795 Jul 29 '14 at 13:14
• @MuhammadUmer Are you looking for color key? – joojaa Jul 29 '14 at 14:50

I like to use the color mixer brush tool. I'm not sure about the english name of the tool since i have the french version of PS. Right click on the brush icon, and take the 4th one. (I have CS5.5) The one with the water drop next to it.

Select the layer of the object you want to blend onto your new background. With the tool work your way around all the edges you want to blend. Experiment with the size and hardness of your brush tool and with the length of your strokes to get the desired results. Use the undo function every time you're not pleased with a stroke. Try starting your stroke on the edge and then try starting more on the object or more towards the background, every time you get a different result.

This is something that requires a lot of "fingerspitzengefühl"

EDIT: I know for sure it's NOT the blur tool. I mentioned a water drop, but i mean the BRUSH+WATERDROP icon. Again, it's under brushes.