Do it with the GIMP


1. Introduction


1.1. History of the GIMP


1.2. Future Directions


1.3. Conventions Used in this Lecture


2. Overview of Features


2.1. Colour Modes

Demo:

  1. Open lena_color.jpg.
  2. Select <Image> -> Image -> Mode -> Grayscale
  3. Select <Image> -> Image -> Mode -> RGB
  4. As can be seen, the image remained in shades of gray. However, now colours can be added.

2.2. 8 bits per colour value

Demo:

  1. Open lena_color.jpg.
  2. Select the "Color Picker" tool from the toolbox.
  3. Click on pixels of the image (or drag while holding the mouse button) and see the colour values that exist there.

2.3. RGB and HSV modes


2.3.1. Demo

  1. Double click the white square at the bottom of the toolbox.
  2. Play with the different colour values.

2.3.2. What are RGB and HSV?

RGB

HSV


2.3.3. What about CMYK?


2.4. Basic Effects using the Toolbox

Demo

  1. Create a new image by selecting: <Toolbox> -> File -> "New..." and filling the dialog.
  2. Draw with the pencil, the paintbrush, and the pattern painter.
  3. Create a Text caption by pressing the "T" tool. (notice that it needs to be anchored by pressing Ctrl+H)
  4. You'll probably want to cancel the text's anti-aliasing. Do that by double-clicking the "T" icon.

2.5. Plug-ins

Demo

  1. Create an image with a text caption.
  2. Invoke <Image> -> Filters -> Blur -> "Blur..."
  3. You can tamper with the settings and then press OK.
  4. The image is now blurred.

2.6. Selection and its Usage

Demo

  1. Open a new image
  2. Select the "Select Rectangular areas" tool
  3. Play with it (try pressing the Ctrl, Alt and Shift keys when selecting, too).
  4. Try other tools and see how they affect the selection.

2.6.1. Using the Red "Paint Selection" Button

Demo

  1. Create a new image
  2. Select some region in it.
  3. Press the red button
  4. Switch colours from black to white and paint the selection.
  5. Switch back to Selection Mode

2.6.2. The "<Image> -> Select" Menu


2.7. Layers

A GIMP image is composed of layers. They can be viewed and manipulated using the Layers Dialog ( <Image> -> Layers -> "Layers, Channels and Paths..." ). These layers can be duplicated , deleted moved, etc.


2.7.1. Alpha

Every layer contains a special layer called the "alpha layer" that specifies its opacity. This layer is treated as a black and white bitmap that can be manipulated with all the normal tools, and in which black is considered full transparency (zero opacity) and white is full opacity between this layer and the layer below it.

The Resultant pixel of the two layers is calculated using the formula:

Result = (1-alpha) * PixelBelow + alpha * PixelAbove


2.7.1.1. Demo 1

Demo

  1. Generate an image with <Toolbox> -> Xtns -> Script-Fu -> Patterns -> "3D Truchet" .
  2. Duplicate the layer using <Layers> -> Duplicate Layer .
  3. Render a nice gradient on the lower layer.
  4. Generate an alpha on the upper layer by using <Layers> -> "Add Layer Mask..." .
  5. Select the paintbrush tool and paint black strokes on the alpha of the upper layer.
  6. Switch to a grey colour and paint grey strokes.
  7. Finalize the Layer's Mask using <Layers> -> "Apply Layer Mask"

2.7.1.2. Demo : Using a Gradient as a Layer Mask

We can also use gradients as layer masks to create all kinds of fading effects.

Demo

  1. Open lena.png.
  2. Create a new layer and make it black (using the new button)
  3. Place it below the lena image.
  4. Add a layer mask.
  5. Switch the colours to white as foreground and black as background.
  6. Draw a foreground to background RGB gradient around Lena's face.

Note

My partner for "Image Processing and Analysis" and I worked for quite some time to create a similar effect in Matlab.

(X .^ 2 + Y .^ 2) .^ (2.5) anyone?


2.7.2. Filters and Layers

Most filters affect only the active layer, so if you wish them to have a cumulative effect on a combination of layers you'll need to merge them first ( <Layers> -> "Merge Visible Layers..." or <Layers> -> "Flatten Image" )


2.7.3. Layer Modes

Layers can be merged using other methods than their Alpha. These are available in the "Mode" combo-box of the layers dialog.

Demo

  1. Generate an image with <Toolbox> -> Xtns -> Script-Fu -> Patterns -> "3D Truchet" .
  2. Duplicate the layer using <Layers> -> Duplicate Layer .
  3. Render a nice gradient on the lower layer.
  4. Change the mode of the upper layer to Screen.
  5. Switch the mode to Addition and then to Subtract and to to other modes.

The operations that are used to merge the various layers are described the in the Gimp User's Manual.


2.7.4. Gradients


3. LUT (Look-Up Tables Effects)

Explanation

Look-up Tables (or LUT for short) are transformations that act on every pixel based on its value alone and not on the values of neighbouring pixels.


3.1. Brightness and Contrast

Question

How can we increase/decrease the brightness and contrast of an image?


3.1.1. Answer

Increasing or decreasing the brightness involves adding or subtracting a certain amount from the value of each pixel.

The contrast can be increased by plotting an y=mx graph according to the value, where m is greater than 1 to increase the contrast, and less than 1 to decrease it.


3.1.2. Demonstration

Demo

  1. Open lena.png.
  2. Show its histogram ( <Image> -> Image -> "Histogram..." )
  3. Close the histogram.
  4. Access the Brightness and Contrast dialog ( <Image> - Image -> Colors -> "Brightness-Contrast..." )
  5. Modify the Brightness and Contrast in some way.

    Note: the entire modified image is displayed in real-time because Brightness and Contrast changes are so easy to calculate.
  6. Open the Histogram dialog again to show its affects.
  7. Repeat if needed.

3.2. Gamma Correction

Question

How can we brighten or darken an image without causing colour values to overflow?


3.2.1. Concept

If we assume that the maximal colour value is 1 and the minimal is 0, then by applying a function of x ** (1/gamma) to every pixel we will modify the histogram while not overflowing from the image boundaries (which cannot be said on brightness and contrast manipulations).

The more positive the Gamma is the brighter the resultant image will be.


3.2.2. Demonstration

Demo

  1. Open the A-Little-Exercise-3.jpg image.
  2. Run <Image> -> Image -> Colors -> "Levels..." .
  3. Raise the value of the middle input box of "Input", and show the difference.
  4. Try to set the brightness/contrast on the original image and see that it doesn't work well.

3.3. Equalize

The "Equalize" operation constructs an appropriate Look-Up Table so that the histogram of the resultant image will be more or less a constant function.

Low colour values will remain lower than higher ones, but the spread of them will change.

Demo

  1. Open the Fifteen-Cent-Ramen-1.jpg picture.
  2. Show its histogram
  3. Equalize it using <Image> -> Image -> Colors -> Auto -> Equalize
  4. Looks Better, doesn't it?
  5. Show its histogram.

3.4. Color Map Rotation

So far we have seen LUTs from the V value to the V value. But there can also be RGB to RGB LUTs. An example of it is the Color Map Rotation which enables us to swap a range of colours with other colours in the Hue spectrum.

Demo

  1. Open tiger_sitting.jpg.
  2. <Image> -> Image -> Colors -> "Colormap Rotation..."
  3. Replace the shades of brown and yellow with purple.
  4. Et voila: The Pink Panther.
  5. Undo.
  6. Convert the shades of green to browns and we get a tiger in the desert.

3.5. Color Balance

Another Useful LUT is the Color Balance. It enables one to increase or decrease the individual components of Red, Green and Blue for either shadows, midtones or highlights.

Demo

  1. Open lena_color.jpg.
  2. Invoke the colour balance dialog by selecting <Image> -> Image -> Colors -> "Color Balance..."
  3. Play with the settings while trying to cancel the over-colouring of the picture as much as possible.

3.6. More LUTs

There are more LUTs present in the GIMP. And if that's not enough you may wish to play with the Gimp::Pixel PDL bindings. (which is the GIMP's answer to the Image Toolbox of Matlab).


4. Basic Areal Effects


4.1. Blur

Question: How can we blur?


4.1.1. Answer to how one can blur an image


4.1.2. Demo of a simple blur

Demo

  1. Open lena.png.
  2. Select <Image> -> Filters -> Generic -> "Convolution Matrix..."
  3. Set the 9 middle squares to 1, the other squares to 0 and the divisor to 9.
    (What we are doing is replacing every pixel with the average of its 3*3 neighbourhood.)
  4. Press the "OK" button.
  5. Repeat several times with Alt+F (or <Image> -> Filters -> "Repeat Last" ) to strengthen the effect.

4.1.3. Gaussian Blur


4.1.3.1. IIR vs. RLE Gaussian Blurs

RLE Gaussian Blur

IIR Gaussian Blur


4.1.3.2. Demo of IIR Gauss. Blur

Demo

  1. Open lena.png.
  2. Select <Image> -> Filters -> Blur -> "Gaussian Blur (IIR)..."
  3. Select radii of x = 5 and y = 5.
  4. Press the "Apply" Button.
  5. Optionally select different images or radii and play with it.

4.1.3.3. Demo of RLE Gauss. Blur

Demo

  1. Create a blank white image.
  2. Place a black text caption on it using the text tool.
  3. Select <Image> -> Filters -> Blur -> "Gaussian Blur (RLE)..."
  4. Select radii of x = 5 and y = 5.
  5. Press the "Apply" Button.

4.2. Sharpening

Question: How can we sharpen?


4.2.1. Answer to how one can sharpen

Demo

  1. Open lena.png
  2. Invoke the "Convolution Matrix" dialog.
  3. Type 12 in the middle square and -1 in the 8 surrounding squares.
  4. Type 4 as a divisor (12 + 8 * (-1) == 4).
  5. Apply.

4.2.2. Sharpening Demo

Demo

  1. Open lena_color.jpg
  2. Select <Image> -> Filters -> Enhance -> Sharpen
  3. Show the results for various levels of sharpening.
  4. A woodcut can be created using a sharpen level of 98.

4.3. Motion Blur

Question: How can we create a motion blur effect?


4.3.1. Answer to how one can motion blur


4.3.2. Demo

Demo

  1. Open tiger_sitting.jpg
  2. Select <Image> -> Filters -> "Motion Blur..."
  3. Choose a direction and a length.
  4. Apply.
  5. Undo and play with the blur settings.

5. Basic Areal Transformations


5.1. Scaling an Image

Demo

  1. Open tiger_sitting.jpg
  2. Select <Image> -> Image -> "Scale Image..."
  3. Increase it by 3 in each dimension. (you can lock them together)

5.1.1. Interpolation

Question: How can interpolation be done?


5.2. The Rotate/Scale/Perspective Tool


5.2.1. Demo

Demo

  1. Open tiger_sitting.jpg.
  2. Select the tiger's face with the rectangular selection tool.
  3. Select the transformation tool and double click it to bring its options dialog.
  4. Use the mouse to control the tranformations.
  5. Create an image with a text caption.
  6. Perform similar operations on the text

6. Some Cool Effects


6.1. Gradient Map


6.1.1. Demo 1 : Real-life picture

Demo

  1. Open g_anwar1.jpg
  2. Select the "German_flag_smooth" gradient
  3. Select <Image> -> Filters -> Colors -> Map -> Gradient Map .
    (That's the GIMP's record for menu depth)
  4. Undo.
  5. Go to the Gradient Editor, create a copy of "German_flag_smooth", and flip it.
  6. Select this copy.
  7. Apply a Gradient Map again.
  8. Experience with other gradients.

6.1.2. Demo 2 : Text Caption

Demo

  1. Create a text caption.
  2. Blur it.
  3. Select a gradient.
  4. Apply a gradient map.

6.2. Fractal Explorer

Demo

  1. Create an empty image.
  2. Invoke the Fractal Explorer with <Image> -> Filters -> Render -> Pattern -> "Fractal Explorer..."
  3. Play with it. (the upper-left preview is zoomable)

7. Turning a Photograph into a Painting


7.1. Oilify

Demo

  1. Open g_anwar1.jpg
  2. Select <Image> -> Filters -> Artistic -> "Oilify..."
  3. Select a mask size and press the OK Button.
  4. Undo and Play with the various settings.

7.2. Gimpressionist

Demo

  1. Open g_anwar1.jpg
  2. Select <Image> -> Filters -> Artistic -> "Gimpressionist..."
  3. Select a preset and press the "Apply button"
  4. Play with the settings in the different tabs if you don't like the preview.
  5. Press the OK Button.
  6. Undo and do it with other images and/or settings.

8. Scripting the GIMP


8.1. The Procedural Database


8.2. Script-Fu Scripting


8.2.1. Interactive Demo

Demo

  1. Invoke the console by selecting: <Toolbox> -> Xtns -> Script-Fu -> Console .
  2. Close all the images.
  3. Create a new image with the background as its filling.
  4. At the command prompt of the console, type (gimp-image-list) and press enter.
  5. Record the index of the image. (it's inside the inner parenthesis)
  6. Type (gimp-image-active-drawable $image) and record the drawable number. (In the GIMP internals, a drawable is a base class for layers and such)
  7. Type (gimp-rect-select $image 10 10 50 80 ADD 0 0) and press enter.
  8. Type (gimp-rect-select $image 40 70 50 80 ADD 0 0) and press enter.
  9. Type (gimp-bucket-fill $drawable FG-BUCKET-FILL NORMAL 100 0 0 0 0) and press enter.
  10. Note: Consult the DB browser for information regarding what every function and parameter here do.

8.2.2. Generating a Logo

Demo

  1. Select <Toolbox> -> Xtns -> Script-Fu -> Logos -> "Bovination..."
  2. Press the button next to "Font:" and select a nice scalable font.
  3. Press OK.
  4. And you have a full-fledged logo.

8.3. Gimp-Perl Scripting


8.4. GIMP (C-based) Plug-ins


9. Finale


General GIMP Links

http://www.gimp.org/ - The GIMP's Homepage. Contains a lot of material and links.

http://gug.sunsite.dk/ - The GIMP Users' Group.

Books about the GIMP

http://manual.gimp.org/ - The Gimp User's Manual. A complete book that covers GIMP 1.0.x with some plug-ins that as of then, were not distributed with it. Still Pertinent as it is very detailed and explains a lot of good techniques.

http://gimp-savvy.com/BOOK/ - "Grokking the GIMP" by Carey Bunks. This book aims to explain the "10% of the tools that are used 90% of the time." I did not read it thoroughly but it looks very nice.

http://www.xach.com/gimp/books/ - Xach's GIMP Books List. Lists, Reviews and links to other books, some of them available only in paper.

GIMP Ports

http://www.gimp.org/win32/ - GIMP for "the other" operating system which is sold by a large Redmond-based company. (All right - it's GIMP for Win32).

http://www.macgimp.org/ - MacGIMP - Gimp for Mac OS X.

Gimp Development

http://www.gtk.org/ - The Homepage of the Gtk+ Toolkit which is the GUI toolkit used by the GIMP

RFC - The Future of the GIMP - This document explains the purpose of the 1.3.x and 1.9.x branches, and what is the workplan for the next releases of the GIMP.

http://www.gegl.org/ - The GIMP 'E' Graphics Library. A sophisticated image representation C library that will be used as the basis for GIMP 2.0.

Miscellaneous Links

The Lena Image (Yahoo) - contains links to information about the neophyte picture that became a standard in the image processing world.


9.2. Origins and Copyrights of the Images

The images used for this lecture can be found in this lecture images directory. This page is meant to detail their origins and their copyright notices.

lena.png

This image is available from this page:

http://www.eso.org/~ndevilla/lena.html - The Lena Story

It is part of a Playboy centerfold and copyrighted by Playboy corporation. The latter, however has given permission to use this particular portion freely for image processing research.

The image there is available in GIF format, but I converted it to PNG.

lena_color.jpg

I found this image here:

http://www.lenna.org/

It seems to be the colour original of the Grayscale one. Usually, the grayscale one is used for image processing research (probably because scientific journals are usually not printed in colour), but I decided to use the colour version here as well.

tiger_sitting.jpg

karakal.jpg

These images were found on the image archive of Gimp-Savvy:

http://gimp-savvy.com/PHOTO-ARCHIVE/

It is copyright-free, so you can do with it as you please.

g_anwar1.jpg

This is a photograph of Gabrielle Anwar, which can be found here:

http://www.candy-fans.com/anwar/index.html

It looks like it was scanned from a magazine, so it's almost surely copyrighted. However, distribution of copyrighted images on the Internet is so common, that I don't think one has anything to afraid of by using this image. Publishing it is a different story, though.

A-Little-Exercise-3.jpg

Fifteen-Cent-Ramen-1.jpg

These images are part of the Propaganda collection of desktop backgrounds.

They are distributed under the GNU General Public License (GPL), which I'm not sure if makes too much sense for images. They were created using the GIMP, but the scripts or the temporary images used to create them are not available as far as I know.