Creating a watermark effect

A nifty effect that can be accomplished easily with The Gimp is the very common watermark effect. Like in the title image for this page, a watermark over a colored background looks just like the background, but lighter.

First some theory

Before beginning the tutorial, I think some of the theory behind the watermark effect would be appropriate. What we want to accomplish with the watermark is the following... we want compress the dynamic range of the image into the rightmost part of the histogram.

Now, what the hell does that mean? Let's begin by taking a nice clouds image and its gray histogram.

Imagine that for every pixel in the color image, you take its luminance value (that's how bright it appears). This value will be some value in the range [0, 255]. On a sheet of paper, you make 256 rows for all of these values and put a tick mark next to the row which corresponds to the luminance value you calculated. In the end, you will have a histogram which counts how many times each luminance value appears in the image (that histogram can be used to analyze the distribution of the luminance values in the image).

If an image has its histogram biased to the left, then the image will have more dark colors than light ones. If it is biased to the right, the image will look lighter than normal. In the above clouds image, there are more mid=tones than dark or light values.

So what we want to do for the watermark effect is to compress the histogram of the original image into a narrower one which will be at the right of the dynamic range. That means we want to make the image lighter, evenly, but without losing information.

At first one might be inclined to just increase the brightness of the image. Using the BCG plug-in, you could select the Additive Brightness mode and increase the brightness with a value of 82. But the Additive Brightness algorithm only adds the specified value to the pixels in the image, and values which result into something larger than 255 get clamped (i.e. we don't support `whiter than white'). This produces ugly results...

The histogram has just moved 82 steps to the right (it does not appear to have the same shape as the first one because of the clamped values). This is no good.

But instead we can use the Stretch Contrast algorithm of the BCG plug-in to compress the histogram. Let's say you give Stretch Contrast a positive value, say 20 (`increase contrast'). SC will turn pixel values of 20 into 0 (black) and pixel values of 235 (equal to 255 minus 20) into 255 (white). The values in-between will be spread evenly in the [0, 255] range.

For negative stretching values, say -20, SC will turn pixels with 0 value (black) into 20, and pixels with value 255 (white) into 235 (again, equal to 255 minus 20). All the values in-between will be evenly compressed into the new range (in this case, [20, 235]). So we can use Stretch Contrast to compress the histogram into a smaller dyamic range. The image will look murky and uncontrasty, but that's just what we want. Here I used a value of -82 for Stretch Contrast:

Note that the histogram now *does* have the same shape as the original one, but it is compressed. We can finally use the Additive Brightness algorithm to `push' the histogram to the right. For the watermark effect, we want to use the same value that we used in the Stretch Contrast step, so that the lightest color will be in fact white (255), and nothing will get clamped. So we use 82 (we can't use -82, because that would push the histogram to the left --- this could be used to evenly darken stuff).

As you can see, the resulting image looks the same as the original one, just lighter (but *evenly* lighter, which is what we want). The histogram has the same shape as the original one, but it is compressed and pushed to the right exactly so that the rightmost value is white and no values got clamped.

And now the fun part

Let's say we want to create a text watermark over a color image. We start with a color image with the background, and a grayscale image of the same size with the text:



Duplicate ORIG, and apply a Stretch Contrast of -63 to it (using the BCG plug-in).


Now invoke the BCG plug-in again and apply Additive Brightness with a value of 63 (positive) to COMPRESSED.


Finally, we will use the Composite plug-in to create the watermark. For the first image use LIGHT, for the second image use ORIG, and for the compositing mask use TEXT.


That's it! We now have a nifty watermark text. You can leave the image as it is. Some people may prefer to add a thin black border to the letters, to make them stand out (some people may as well say that this kills the watermark effect, but hey, what the hell; it may be useful). To do this, perform an Edge Detection of TEXT with a value of 10.0, Contrast Autostretch the resulting image, and Invert it:


Finally, multiply WATER0 by EDGE to get the final result.


You can later experiment with different contrast and brightness values for the watermark creation process. Enjoy!

Send comments, bug reports, and other stuff to That's Federico Mena Quintero.

This page last updated: 1996/07/05 10:59:14