Home:Equipment:Technique:Retouching

Sky Replacement Without Halos

20th Feb 2006, sjh


1) Overview

This tutorial is of a technique for replacing one of the white cloudy skies in a photo with something more appealing. It isn't too hard to just select the white sky, and replace it with a blue sky from another photograph, but where you can get into trouble is when there there are a lot of edges with the strong white of the sky bleeding into them. That can leave halos around the branches and leaves.

The problem comes about because you are changing from a white-green transition to a transparent-green transition, and even once you apply a layer mask based on luminosity, the white stays around. If you cut off the transition region, the leaves seem too small and disconnected, or if you leave it in, you get white halos. What we really need here is a way of removing the white altogether and turning the whiteness into transparency. One way of doing this is the multiply mode, which is what is used in this tutorial.

Before → After

Procedure Summary

  1. Add a sky layer on the background with blend mode to multiply.
  2. Duplicate original layer and place on top.
  3. Add a layer mask to top layer set to inverse of image itself.
  4. Tweak layer mask with curves.
  5. Blur layer mask.
  6. Whiten out mask in other areas of the image.

Currently this tutorial is only available for The GIMP. A Photoshop version may come soon, although mostly the same approach can be followed.

2) Procedure

I am starting with this crop out of an image with a white sky.

If the sky isn't fully white, you may need to duplicate the lower layer, and adjust the curves until it is white, or otherwise it will show through in the multiply step following

Adding A Sky

The first step is to find a suitable sky image. I'd generally suggest there are some clouds in it to help with the feel of realism of lighting and to add some interest. You may need to first scale it to a suitable scale, and keep in mind that different parts of the sky have a different gradient, so it is useful to choose an image with the horizon about the same level in the picture.

Cut and paste the image as a new layer on top of the background, and then set the layer blend mode to multiply.

Restoring Opacity

The multiply gets things quite close, but there is the problem that the sky shows through the rest of the image. This can be fixed using a layer mask. One way is to apply a mask to the sky layer, but I am instead going to copy the original image back over the top and apply a mask to it. The idea of that is so the sky can easily be replaced again, and the transparency is a property of the image, and not the sky.

Here duplicate the bottom layer, bring that new layer to the top, add the layer mask, and copy the top layer image into the mask itself. Then invert the colour on the layer mask. That way bright parts in the image will be dark in the mask, so making that part of the layer invisible, allowing the blue to show through

  1. Right-click on the top layer and select Add Layer Mask. Now the layer will consist of two separate layers: the layer itself, and the mask layer which determines how opaque the layer is at each pixel.
  2. (GIMP Specific) In the dialog, choose to initialise the layer mask to Grayscale Copy of Layer, and tick the box to Invert Mask
  3. Alternatively if your editor doesn't give the above options when creating the mask:
    1. Click on the top layer icon showing the image itself
    2. In the image select all and copy
    3. Click on the top layer mask icon
    4. Now paste into the image
    5. Invert the image black-for-white. If there is no option to do this, you can use curves with a straight line from the top-left to the bottom-right.

Completely Opaque

Adding the layer on top helps with the opacity, but there is still sky showing through where it shouldn't be.

One step is to get out the lasso select tool, or your selection method of choice, and select all the broad areas of the image that are not adjacent to the sky. Select these, and use the fill tool to paint the mask white.

We can fix that some more with some curves fiddling on the layer mask to make the top layer more opaque. This tuning process may benefit from using the curves on selected areas at a time if there are varying brightness areas of the image.

Restoring Contrast

This method can wash out some of the contrast in the edges. One way to restore that again is to apply a gaussian blur to the mask, with a fairly small radius. This should make the image appear a bit sharper. (This is a bit like the unsharp-mask, where blurring of one element has a sharper effect overall.)


Related Pages