# Help:Editing/Image translucency

 This page is currently under construction.The information contained within should not be considered fully accurate and/or complete.

## Overview

This is a detailed guide on one method for adding translucency to images on the wiki. Translucency is when part of the item/object is partially transparent, so simply cutting out around the item is not sufficient to remove the background. Category:Images needing translucency contains a list of all images that need this done. This requires rather advanced image editing skills and is not recommended for beginners, it is additionally suggested that one use a graphics tablet. It requires: experience editing images, basic grasp of algebra, understanding of colour theory and various colour models and a fair amount of patience, but the results are spectacular.

## Understanding the theory

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

${\displaystyle \mathrm {original} =\mathrm {background} *(1-\mathrm {alpha} )+\mathrm {foreground} *\mathrm {alpha} }$

where

${\displaystyle \mathrm {original} }$ is the unedited image
${\displaystyle \mathrm {background} }$ is the area of the image behind the model
${\displaystyle \mathrm {foreground} }$ is the colour of the model with translucency turned off
${\displaystyle \mathrm {alpha} }$ is the alpha value of the pixel, applied to the ${\displaystyle \mathrm {foreground} }$ colour

This formula can be memorised using the mnemonic

Barrows 1 Awards For 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

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 ${\displaystyle \mathrm {foreground} }$ gives us

${\displaystyle \mathrm {foreground} ={\frac {\mathrm {original} -\mathrm {background} *(1-\mathrm {alpha} )}{\mathrm {alpha} }}}$

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

${\displaystyle \mathrm {alpha} ={\frac {\mathrm {background} -\mathrm {original} }{\mathrm {background} -\mathrm {foreground} }}}$

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

${\displaystyle \mathrm {background} ={\frac {\mathrm {original} -\mathrm {foreground} *\mathrm {alpha} }{1-\mathrm {alpha} }}}$

### Blend modes

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

Blending mode Formula
Linear Dodge ${\displaystyle \mathrm {target} +\mathrm {blend} }$
Difference ${\displaystyle |\mathrm {target} -\mathrm {blend} |}$
Multiply ${\displaystyle \mathrm {target} *\mathrm {blend} }$
Color Dodge ${\displaystyle {\frac {\mathrm {target} }{1-\mathrm {blend} }}}$

where ${\displaystyle \mathrm {blend} }$ is our current layer, and ${\displaystyle \mathrm {target} }$ 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 ${\displaystyle a,b,c}$ where ${\displaystyle a}$ is the top layer and ${\displaystyle c}$ is the bottom layer, and we were to apply a Multiply to ${\displaystyle a}$ and a Linear Dodge to ${\displaystyle b}$, this would be the same as the calculation ${\displaystyle a*(b+c)}$, since ${\displaystyle b}$ would be calculated before ${\displaystyle a}$.

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

So, let's have a go at converting our foreground formula into layers.

${\displaystyle \mathrm {foreground} ={\frac {\mathrm {original} -\mathrm {background} *(1-\mathrm {alpha} )}{\mathrm {alpha} }}}$

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.

${\displaystyle \mathrm {foreground} =(\mathrm {original} -(\mathrm {background} *(1-\mathrm {alpha} )))/(\mathrm {alpha} )}$

As we can see when we look at our equation, the order we would usually take when calculating the formula is

${\displaystyle 1:(1-\mathrm {alpha} )}$
${\displaystyle 2:(\mathrm {background} *(1-\mathrm {alpha} ))}$
${\displaystyle 3:(\mathrm {original} -(\mathrm {background} *(1-\mathrm {alpha} )))}$
${\displaystyle 4:(\mathrm {original} -(\mathrm {background} *(1-\mathrm {alpha} )))/(\mathrm {alpha} )}$

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 ${\displaystyle 1}$ is our bottom layer, and ${\displaystyle 4}$ is our top layer.

Layer ${\displaystyle 1}$ - 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 ${\displaystyle 2}$ 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 ${\displaystyle 3}$ 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 ${\displaystyle 4}$ 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 ${\displaystyle 1-(1-\mathrm {alpha} )}$ which, of course, would resolve to ${\displaystyle \mathrm {alpha} }$. With Color Dodge placing the ${\displaystyle target}$ on top and the ${\displaystyle blend}$ 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
${\displaystyle 4}$ Inverted ${\displaystyle \mathrm {alpha} }$ Color Dodge
${\displaystyle 3}$ ${\displaystyle \mathrm {original} }$ Difference
${\displaystyle 2}$ ${\displaystyle \mathrm {background} }$ Multiply
${\displaystyle 1}$ Inverted ${\displaystyle \mathrm {alpha} }$ None

A list of layer set ups can be found in the Quick References section at the bottom of this article.

## Examples

 This page is currently under construction.The information contained within should not be considered fully accurate and/or complete.

Need to write this up properly, but here's a load of pretty images and some regurgitated words

### Set up

1. 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.
2. 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.
3. Create two layers for the background, one using the RS Wiki's Light theme background (#fbfbfb); one using the Wiki's Dark theme background (#172136) Place these two on the bottom, and hide or display as necessary.

### Step 1: Cutting out the opaque sections

First, we'll remove all areas of the image that we know aren't opaque.

1. Going around our model with the Polygonal Marquee tool or the Pen tool, we select the model itself, attempting to get the selection as accurate as possible. It's okay if we have areas of the original background showing at this point, as we'll be cleaning the edge up shortly.
2. Use this selection to create a layer mask which we'll apply to the opaque layer we created when setting up.
3. Using both dark and 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. Since we have a layer mask, it can often be easy to use the Smudge tool set to 100% to gently push the green sections out of the visible area, leaving a believable colour in its place.

### Step 2: Recreating the background

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 focus on the parts of the image where we know or suspect translucency exists.

### Step 3: Putting our theory to use

Now that we have our background, there are multiple possibilities. What we do next will depend entirely on the image we're working with.

1. We take the difference between the original image and the background to see if there's anything we can take from it. In our example here, we can see that it looks as though we have our translucent areas on a black background. This is good, but we still need to separate the two.
2. Merging our layers, we use the Desaturate tool on the resulting layer to make a reasonable estimation of the alpha.
3. With our alpha channel and background estimated, we now set up our layers, using the Quick References at the bottom of this guide for convenience. In this case, we'll be using the layer set up for calculating ${\displaystyle \mathrm {foreground} }$, remembering to invert our alpha channel for the calculations, and applying the appropriate blend modes to each layer.
4. We now have our foreground colours.
5. We make a copy of our alpha channel and invert it back, merge the layers we're using to calculate the foreground together, then finally apply the alpha channel as a mask to the resulting layer. All we need to do now is ensure that the layer order is correct and clean up the image.

### Step 4: Cleaning up the image

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 (the foreground in this case).

1. 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, so we're going to need to clean this up by using the Smudge tool on the translucency layer mask to push our alpha values into the model, hiding them behind the opaque layer. This technique is only required in areas where there's translucency present, everywhere else can simply be cut out.