A blog on software engineering by Trevor Brown

Premutliplied Alpha in GIMP

Watch Premulitplied Alpha in GIMP
This tutorial is 3.5 minutes long.

If you have ever rendered an image in Blender and decided to do the final composition in GIMP you may have discovered that when you placed your foreground layer over the background layer a nice fuzzy black line (fringe) appeared around the edges of your foreground objects. This is because you were using premultiplied alpha in Blender. GIMP does not have a way to handle premultiplied alpha and it causes the foreground layer to have fringe around the edges. I have spent hours trying to get rid of black fringe on images with premultiplied alpha in GIMP. In this tutorial I will share a solution of removing the fringe caused by premultiplied alpha.

Here I have the foreground image with a white monkey on a transparent premultiplied alpha background and a white background image.

foreground_layer background layer

First load both the foreground and background layers into GIMP, making sure the background layer is on the bottom. You can see here the black fringe clearly visible against the white background.

fringe closeup

Now hide the background layer and view the channels. Select the alpha channel and drag it down to the box below. You now should have a copy of the alpha channel. Before you do the next step switch the background and the foreground colors so that the background color is black, as shown.

background and foreground colors

In the layer tab, right click on the foreground layer and click “Remove Alpha Channel”. Now add a layer between the background and the foreground layers and fill it with black. Now right click on the middle layer and select “Add Layer Mask”. A dialog will come up with several different masking options, choose “Channel” and select the layer we just copied from the drop-down menu. Now make all the layers visible. Select the foreground layer and set the blending mode to “Add”. Your setup should look like this.

final layer setup

Now you will still probably have some fringe, so click on the middle layer’s mask and use the Curves tool to remove the fringe. Click on center of the curve and pull it down some until you don’t see any fringe. If you pull it down too far you will see white fringe.

curve setting

That’s It! you should now have a fringe free white foreground on a white background!

fringe free border