User:Sahima Badir/Removing backgrounds from images needing translucency
Overview[edit | edit source]
|Member requirement||Free to play|
|Official length||Several hours to half a day|
|Requirements||Skill requirements are not boostable unless marked with a [B] for boostable.
|Items required||Items from the tool belt are not listed unless they do not work or are not automatically added.|
|Enemies to defeat||
Understanding the theory[edit | edit source]
Before we can start removing backgrounds from images effectively, we first need to understand the basics of how games and websites render translucency. Although there are different ways to blend two images together, the most basic and fundamental method is alpha blending, and is the only method we need to understand in this context. Alpha blending is represented as
- is the unedited image
- is the area of the image behind the model
- is the colour of the model with translucency turned off
- is the alpha value of the pixel, applied to the colour
This formula can be memorised using the mnemonic
Barrows 1 Awards F--- All
Memorising this equation is vital, and our goal will be to first recreate the image's background, then recreate either the alpha channel or the model's colour, so that we can then calculate the remaining elements of the image by rearranging our formula.
Rearranging the formula[edit | edit source]
Most images fall into one of two categories. Either the foreground colours are easy to predict, or the alpha values are easy to predict. In both situations, we'll want to rearrange our formula for the remaining variable.
When our image we are working with contains a particularly complex texture, or the translucent areas may otherwise be difficult to properly estimate or recreate, it is preferable to estimate the alpha channel. Rearranging our formula therefore for gives us
When our image uses translucency whose colour can be predicted but contains varying alpha values, such as models that glow, it is preferable to estimate the colour of the translucent areas. Our rearranged formula is
but this value will be calculated for each channel separately and must therefore be handled appropriately. Our first option is to apply the calculation in greyscale so that we end up with a single result. Our second is to perform the calculations in full colour, then multiply our image by itself and add the channels together, using either the Calculations feature in Photoshop, or the Decompose / Recompose feature in GIMP. This option is more accurate, but also more involved.
Although we have no immediate need to calculate the background, it can occasionally be useful to estimate the alpha and foreground values first, then use them to calculate the background, thus allowing us to recalculate the first two more precisely. This concept won't be covered, but should the need arise, our rearranged formula would be
Blend modes[edit | edit source]
Having rearranged our formula, we'll now need a way of calculating the remaining element within our chosen editing software. Unfortunately, there are no features that calculate these for us, so we have to use blending.
The four blend modes we'll need to remember are
where is our current layer, and is the blended result of all the layers below.
A painter's algorithm is traditionally used when calculating blending, so we can assume that the further down a layer is, the earlier it will be calculated. This means that if we had layers where is the top layer and is the bottom layer, and we were to apply a Multiply to and a Linear Dodge to , this would be the same as the calculation , since would be calculated before .
Blending our layers together will allow us to calculate the formulae we rearranged earlier, with each mode providing us access to our basic operators - addition, subtraction, multiplication, and division.
Layer setup[edit | edit source]
So, let's have a go at converting our foreground formula into layers.
Firstly, to simplify the problem, we'll place brackets around our variables to explicitly define the order of operations. Every time we apply a blend mode to a layer or layer group, it will represent a single calculation being performed on two sets of brackets, thus we wish to structure our equation in such a way that we can easily see which operations need to be performed first.
As we can see when we look at our equation, the order we would usually take when calculating the formula is
Now that we've sorted out the order of operations we need to perform, let's have a look at the blend modes. Since layers further down are calculated first, we assume that is our bottom layer, and is our top layer.
Layer - our bottom layer - is inverted. Although we can calculate this by placing a layer filled with the value 1 - white - above the alpha channel, it would be easier just to invert our alpha channel and use it as it is. It therefore requires no blending.
Layer is a simple multiplication. As we have our inverted alpha channel on the bottom, all there is to do is place the background layer above it, and set its blending to Multiply.
Layer is just as simple. We place the original image above the background layer, then set its blending to Difference. Because Difference uses the absolute value, the order of the layers in the subtraction is irrelevant.
Layer is the division. This is a little trickier. Color Dodge will give us our division, but we first need to deal with the inversion in the denominator. As with before, it would be possible to use a white layer with the blending set to Difference to perform an inversion, but we're again working with just a single layer, so we should just invert it. When Color Dodge inverts it again, it will be the same as calculating which, of course, would resolve to . With Color Dodge placing the on top and the on the bottom, this makes it a lot easier for us since we won't have to create a layer group to apply blending to. Our inverted alpha channel now becomes our top layer, with a blending of Color Dodge.
We are left with our layer setup
|Layer description||Layer blending|
A list of layer set ups can be found in the Quick References section at the bottom of this article.
Examples[edit | edit source]
Need to write this up properly, but here's a load of pretty images and some regurgitated words
Set up[edit | edit source]
- Create an original image layer for back up and comparison; place this on top so we can toggle between our attempt and the original image. Our goal is to have our attempt (with the estimated background layer visible) as close to the original image as possible.
- Duplicate the layer so that we may use this for the opaque areas of our image (right now, this will be the same as our original image)
- Create two layers for the background, one using the RS Wiki's Light theme background; one using the Wiki's Dark theme background (need to figure out how to link these, given they're both data:images and not URLs) Place these two on the bottom, and hide or display as necessary.
Step 1: Cutting out the opaque sections[edit | edit source]
First, we'll remove all areas of the image that we know aren't opaque.
- Going around our model with the polygonal marquee, we select the model itself, attempting to get the selection as accurate as possible.
- Use this selection to create a layer mask which we'll apply to the opaque layer we created when setting up.
- Using the dark or light background layers for contrast, clean up the edges of the model with the Clone Stamp tool, the Brush tool, or the Smudge tool, depending on practicality
Step 2: Recreating the background[edit | edit source]
Recreating the background varies in complexity from image to image. Every time we do this, we want to ensure that it's as close as we can get it, which will reduce artefacts later on. In this example, we have a screenshot taken by a lovely person who understands the true value of a solid green background, so recreating it should be simple. We only need to concern ourselves with parts of the image where we know or suspect translucency exists.
Step 3: Putting our theory to use[edit | edit source]
(Need to write up how to evaluate this properly, but here's a simple example) Now that we have our background, there are multiple possibilities. What we do next will depend entirely on the image we're working with, but imma explain that here in a later draft of this guide kthx
- We take the difference between the original image and the background to see if there's anything we can take from it (there usually is, but it's not guaranteed). In our example here, we can see that it looks as though we have our translucent areas on a black background (and a load of green stuff where the opaque areas are - this is to be ignored for now). This is good, but we still need to separate the two.
- Merging our layers, we use the Desaturate tool on the resulting layer to get a reasonable estimation of the alpha. Seriously, I'd be happy if even a tenth of the images were this bloody easy.
- With our alpha channel and background estimated, we mosey on down to the Quick References section of this guide, and set up our layers to the layer set up for calculating , remembering to invert our alpha channel for the calculations, and to apply the proper blend modes to each layer.
- Look at this hot mess, there be our foreground colours. If it was good enough for Jesus, it'll be good enough for you.
- Merge our layers together, not forgetting to back up our alpha channel and invert it back to what it was originally, then apply the alpha channel as a mask to the resulting layer. Show the foreground layer, which is now showing us our translucency, and the opaque layer, and we now have our image. Nearly.
Step 4: Cleaning up yo ship[edit | edit source]
In all likelihood, our background won't have been perfect. In this case it was, because of the lovely solid green background, but we'll usually need to clean up whatever it was we calculated (foreground in this case).
- This example is so uncharacteristically easy that our colours are entirely non-problematic, but we've also ended up calculating the opaque areas as well, since we didn't specifcy the translucent areas exactly, so we're going to need to clean that up by Smudging our translucency alpha values into the model, to hide them behind the opaque layer.
Quick References[edit | edit source]
Layer description Layer blending Inverted Color Dodge Difference Multiply Inverted None
Layer description Layer blending Group Color Dodge White layer Difference Difference None Difference None
Layer description Layer blending Color Dodge Difference Multiply None