Rambo Tribble’s Gimp Tutorials – The Contrast Filter

In outdoor photography, ambient lighting is rarely cooperative. It is said that Ansel Adams would sometimes sit for weeks on end waiting for the light to favor one of his shots of Yosemite. Unfortunately, this isn’t a practical approach for most of us.

The good news is that many underexposed photos can be saved with just a few minutes work in the GIMP. Using the GIMP to apply contrast filters can pull out details lost in the murky dark of an underexposed image. Take as an example, the following photo of a Great Horned owl by my wildlife-photographer friend, Stephanie Hazen.

original owl photo

Before editing

image after editing

Contrast filter applied

First, download the original photo to work on. In most browsers, just right-click on the first photo, g_h_owl_01.jpg, and choose to save the image from the menu that appears. Then, open the photo in the GIMP and we’ll start by making a copy of the base image onto a fresh layer. The duplicate layer button on the Layers dialog window does the job nicely. This new layer will become the actual contrast filter that will then be applied to the base image, below. The base image also can serve as a convenient reference; just toggle visibility on the filter layer to see the original. Figure 2 illustrates the starting point with the duplicate layer. When created, the new layer will be named “Background copy”. To give it a more meaningful name, right click on the layer entry in the Layers dialog box and choose “Edit layer attributes”. I’ve given the layer a label of “Contrast filter 1”, in the example below. Note: WordpPess refuses to display the screenshot images at their specified size, making them almost impossible to read. If you right-click on the image and choose to view it alone, it should render at a readable size.

Photo with duplicate layer

Figure 2: The photo with duplicate layer

The next step in creating the contrast filter is to desaturate the layer that will become the filter. In the “Colors” menu, choose “Desaturate” and the related dialog box will appear. It will ask what basis you want to use to determine the shades of gray used in the process. The default, “Lightness”, will work fine, so just click “OK”. The result is a black and white rendition of your photo.

Desaturation dialog and preview

Figure 3: The Desaturation dialog and preview

Next, we invert the colors of the desaturated image layer by choosing “Colors — Invert” from the menu. The result is shown in Figure 4.

Color-inverted, desaturated layer

Figure 4: Color-inverted, desaturated layer

One more step is required before we can apply our contrast filter layer, that is to add some blur to the layer. We do this because, if we don’t, the result of applying our filter layer to the base image will be to cause the edges in the photo to become pixelated or “jaggy”, much like the result of an excessive application of sharpening to an image.

Open the “Filters” menu and choose “Gaussian Blur” from the “Blur” fly-out menu. The Gaussian blur dialog box will appear. You’ll need to choose a blur radius appropriate for your image. With most full-resolution photos, a blur radius of 20 pixels is usually a good choice, but I find with smaller images such as the example, a smaller radius gives a sharper result. I have chosen 12 pixels for that reason, in the example.

The Gaussian blur dialog

Figure 5: The Gaussian blur dialog

Now we are ready to turn our layer into a contrast filter by applying the layer mode, “Overlay”, in the layers dialog. Simply choose “Overlay” from the mode drop down menu found near the top of the “Layers” dialog box. The result is shown in Figure 6.

The resulting contrast filter

Figure 6: The resulting contrast filter

As you can see, the dark areas in the photo are now lightened to allow their details to come out. Perhaps less noticeable, the bright areas have been subtly attenuated, meanwhile the midtones are untouched. This is what a contrast filter does; it flattens the contrast of an image. This compares well to the more common practice of using a brightness or color curves tool to make the adjustments, often resulting in a washed-out image. This, in turn, often leads the user to compensate by increasing saturation, usually giving an artificial quality to the colors.

In this example, the result is pretty good with the filter layer’s opacity set to 100%, but it is usually desirable to lower the opacity of the filter to get a more life-like result. Of course, that is easy to do with the layer dialog’s “Opacity” setting slider.

While this new image is clearly an improvement on the original, the owl’s face is still too dark to reveal his piercing gaze. Next we will apply another contrast filter to just his eyes by using the layer mask feature of the GIMP.

The first step is simply to create a duplicate of our contrast filter layer. Again, just use the “Create duplicate layer” button at the bottom of the “Layers” dialog box. The initial result will be an image that is blown-out with bright colors, but don’t worry, we’ll fix it.

Next, right-click on the new layer’s entry in the dialog window. From the fly-out menu that appears, choose “Add Layer Mask”. The “Add Layer Mask” dialog box will open, as shown in Figure 7.

Adding the layer mask

Figure 7: Adding the layer mask

In the add layer mask dialog, choose to initialize the new layer to “Black (full transparency)”. When you click on the “Add” button, the new layer will disappear and your image will appear as it did in Figure 6. We will now paint on the layer mask with white to reveal the brightened eyes the layer produces.

To do our painting, the easiest tool to use is the radial gradient. Choose the gradient, or “Blend”, tool in the Toolbox, (the toolbox is usually positioned to the left of the image window). Make sure that white is your foreground color. In most cases, you can just click on the double ended arrow on the upper right above the display of foreground and background color, found between the toolbox icons and the tool option settings below. This will switch the foreground color, (usually black), with the background color, (usually white).

Next, click on the gradient sample in the tool options section. From the fly-out menu, select the gradient, “FG to Transparent”. Finally, click on the “Shape” icon and select “Radial”. We are now ready to proceed with bringing out the owl’s golden peepers.

Start by placing the cursor in the center of one of the owl’s eyes. Click and drag the cursor outward from the eye’s center to a distance at least twice the radius of the owl’s eye. Figure 8 shows what this process looks like.

Using the gradient tool

Figure 8: Using the gradient tool

Bear in mind that the gradient will transition to transparency at the halfway point of the distance you have dragged. When you release the mouse button, the eye will suddenly brighten, as the top contrast filter layer’s effect becomes visible in just that area. If you didn’t get all the area you wanted to brighten, you can simply repeat the process. Do the same thing to the other eye and you are finished. Again, in some cases you might want to adjust opacity, but with this image it probably isn’t necessary. Figure 9 shows the finished product.

The eyes have it

Figure 9: The eyes have it

Before we leave, let me explain a few things about what we have done. First, the way an overlay layer works is to combine the color intensity, or brightness, in the overlay layer with the layer below. By creating a reverse of the image’s light and dark areas, through desaturation and color inversion, we have created a perfect brightness-reversed map of the high-contrast areas. Note that an overlay layer doesn’t affect an image where the layer is at a 50% gray; it only has effect in the lighter and darker areas. An easy way to see how this works is to create a transparent layer over an image, make it an overlay, then paint on it with various intensities of white, gray, and black brushes.

The gradient tool is often the best choice when you want to blend one layer into another, seamlessly. It offers a smoother transition than feathering a selection and allows you to paint one layer into the other, as you have just seen.

One thing to be aware of is making sure you have the layer you want to work on selected in the layers dialog. If you are trying to modify a visible layer and nothing appears to be happening, chances are you don’t have the layer you’re looking at selected. This also means that the layer that is selected will have the modifications applied to it and you’ll probably need to undo those changes before proceeding.

Finally, a great strength of using a contrast filter or compounded contrast filters is that such filters don’t alter the direction or other characteristics of the ambient light, just its apparent intensity. The balance of key, back and fill lighting remains essentially untouched.

Well, that’s it and remember, it’s really pretty lame not to use the GIMP to improve your photos.