CS 424, Fall 2017:
Gimp 2: Selections, Paths, and Layers
This lab continues the introduction to Gimp that we started last week. It will introduce you, briefly, to some of Gimp's more advanced features. The lab adds three new exercises, which should be submitted into the same folder as the five previous exercises. Remember that I will look for your work one week after today's lab. Note that for Exercise 8 you should turn in an xcf file, as noted below.
A general note... Sometimes it is helpful to work on a magnified image. At high magnification, it is even possible to edit individual pixels in the original image. The "View" / "Zoom" menu can be used to control the magnification level. Note that the 1, 2, 3, 4, and 5 keys can be used to quickly change the magnification (just hit the keys, with no Control or other modifier key).
More About Selections
You already encountered selections last week, but there's a lot more to learn. One of the most important is that a pixel can be partially selected. That is, a selection is not necessarily just an outline; it's really an assignment of a "degree of selectedness" to each pixel. For example, the Cut command (Control-X) deletes the content of a selection. A fully selected pixel is set to transparent (if the image has an alpha component) or to the background color (if there is no alpha component). However, a partially selected pixel will only be partially cut. If there is an alpha component, the pixel becomes translucent; if not, the background color is blended with the current color of the pixel. Similarly, when you fill a selection, the current color of a partially selected pixel is blended with the fill color. This is very much like alpha blending, with the degree of selectedness playing the role of the alpha component.
One way to get partially selected pixels is to "feather" a selection. When a selection is feathered by, say, 10 pixels, the sharp boundary is replaced by a 10-pixel-wide border, with the degree of selectedness decreasing from one to zero across the width of the border. Use the "Feather" command in the "Select" menu to feather the current selection. Alternatively, selection tools, such as the Rectangle Select tool, have a Tool Option that will automatically feather the border of any selection that you create with the tool.
Exercise 6. Use a feathered selection to create an image like the one shown at the right. The image is a PNG file that becomes transparent around the edges so that it blends with the background of the image. You can follow these instructions to do the exercise:
- Open an existing image file in Gimp. You might want to scale the image, if it is too big. I used a cactus flower from Wikimedia Commons. You should use a different image, either one of your own or one from /classes/cs424/gimp-pics. (Note: I applied the "Artistic" / "Oilify" filter to the cactus flower because I liked the effect.)
- This exercise requires an alpha component for the image. A PNG image might already have one; a JPEG definitely will not. To add an alpha component, find the Layers dialog in the upper right of the Gimp window. (There is an illustration of the dialog later on this web page.) Right-click the white area of the dialog, and select "Add Alpha Channel" from the popup menu. (It's close to the bottom.) If the image already had an alpha channel, the command is disabled.
- Make a selection around the part of the image that you want to keep. Be sure to leave space between the selection and the boundary of the image to allow for feathering. The example uses an elliptical selection.
- Use the "Select" / "Feather" command to feather the image by a rather large amount, say 40 or 50 pixels.
- You want to cut away the outside of the selection, but the Cut command removes the inside of the current selection. The solution is to invert the selection, which reverses the outside and the inside. Use the "Invert" command in the "Select" menu to do that.
- Apply the "Cut" command, Control-X.
- You might want to crop the image, so you don't have a huge transparent border around the edge. To do that, make a rectangular selection around the part you want to keep, and use the "Crop to Selection" command from the "Image" window.
- Save your image using the "Export As" command in the "File" menu. Be sure to save it in PNG format. That is, use a file name that ends with .png. And remember to use a name such as "ex6.png" or "exercise6.png" so that I will be able to identify it.
Gimp users often put a great deal of work into creating a selection. One way to get more control over selections is with the Path tool, which is discussed below. Another is the "Quick Mask," which gives you complete control of the degree of selectedness of individual pixels. Use the "Toggle Quick Mask" in the "Select" menu to turn the Quick Mask on and off. When the Quick Mask is on, the current selection is represented as a translucent pink overlay on the image. The degree of transparency corresponds to the degree of selectedness of the pixel. The overlay is completely transparent for fully selected pixels. Painting tools will affect the mask rather than the image. For example, drawing with black will add to the mask (and therefore subtract from the selection), and drawing with white, or erasing, will subtract from the mask. When editing the quick mask, consider using the pencil tool instead of the bursh tool. The pencil tool is the same as the brush tool, except that it does not do any transparency or antialiasing.
A "path" in Gimp is a Bezier curve. Paths are not visible in the actual image, but you can "stroke" a path to make it visible. Paths are not selections, but they are closely related. You can convert a path into a selection, or a selection into a path.
Paths are created using the Path tool (the eighth tool in the Toolbox). To create a path, click a sequence of points with the Path tool. Optionally, you can make a closed path by control-clicking back on the first point. This gives a polygonal path. You can then drag on one of the sides of the polygon to change it from a straight line into a curve. When you do that, the usual Bezier control handles will appear at the endpoints of the curve. You can drag the ends of the control handles for finer control of the shape. At a point where two segments of the curve join, there are two control handles. If you hold down the shift key while dragging, the two handles are constrained to be a straight line and to have the same length, which makes the curve smooth at that point.
Paths are ordinarily not visible except when they are being edited with the Path Tool. However, any path that you create is saved the to Path Dialog. The Path Dialog is one of the four tabbed dialogs in the upper right of the Gimp window. Initially, it is hidden by the Layers Dialog. Click the Paths tab to see the Path Dialog. (See the illustration of the Layers Dialog, later on this page.) The Paths Dialog contains a list of paths. Right-click a path to get a popup menu, which will include commands such as "Path Tool" to go back to editing the path with the Path Tool; "Path to Selection" to convert the path into a selection; and "Stroke Path" to draw line or drag a paint tool along the path.
Exercise 7.Make a heart-shaped path, and do something interesting with it. Save the image to show your work. It would be nice to use more paths to make some additional shapes in the image. This illustration explains how I made a red heart with a black outline—but you should not simply make the exact same thing:
Layers are a very important feature in Gimp, and one that can easily lead to confusion if you don't understand what they are and how they work. In Gimp, the final image can be composed from a stack of layers. Each layer is itself an image. The final image is composed by starting with a blank canvas, then copying each layer to the canvas, one after the other, in order from the bottom of the stack of layers to the top. The layers don't have to be the same size as the canvas. They can be translucent, and they can have transparent parts. The advantage of this is that you can edit one layer without changing the others. You can move a layer (with the Move Tool)—and the stuff in the lower layers will be still be there.
It is important to understand that only one layer can be edited at any given time. That layer is called the active layer. This can be annoying if you lose track of which layer is active. It can be especially annoying if the active layer is hidden in the visible image or has been made completely transparent!
Layers are listed in the Layer Dialog, which can be found in the upper right corner of the Gimp window. The active layer is highlighted in the list of layers. Click a different layer in the list to make it active. Right-click the dialog for a popup menu of commands for working with layers. Some of the commands are duplicated in the "Layer" menu. If the right-click is on one of the layers in the list, the popup menu will also include commands that apply to that individual layer. Here is an illustration of the dialog from a project that uses four layers (actually, my solution to an older version of the final exercise):
A new image will only have one layer. You can add a new layer with a command in the "Layer" menu or in the popup menu that you get by clicking the Layer Dialog. New layers are also added automatically in some cases. The Text Tool, in particular, always creates a new layer. Text layers are special. They only contain text, and they can only be edited with the text tool. (More exactly, if you edit a text layer with some other tool, it is converted into a regular layer, and you can no longer edit it as text.)
The Paste command will also create a new layer. In this case, the layer is special because it is a "floating" layer. The Move Tool will automatically be selected, and you can use it to drag the floating layer to the desired position. Before you do anything else, you need to either "anchor" the layer (that is, make it part of the active layer), or convert it into a regular layer. To anchor it, just click outside the pasted layer. To convert it into a regular image, right click on its entry in the Layer Dialog, and use the "To New Layer" command in the popup menu. (There will also be an "Anchor" command in the menu.) Again, this behavior can be annoying if you don't know about it.
Important Note: For this exercise only, I would like you to turn in the .xcf file for your project, and not just the final .jpg image. An xcf file is created using the "Save" command in Gimp, and it contains full information about the structure of the project. In particular, it will show me how you used layers in the project.
Exercise 8. For your final Gimp exercise, you should replace Alexander Hamilton in an image of a ten-dollar bill with a picture of yourself—or someone else if you prefer. You can even use an animal or flower or whatever, instead. You can find the original ten-dollar-bill image in /classes/cs424/gimp-pics. It is strongly suggested that you use layers to do the exercise, since you will find it easier to get things right if you do. For my solution, I used a picture of a well-known faculty member from our faculty page. (In your project, don't use the same person that I used.) Here is my minimal solution:
Note that I have adjusted the colors of the inserted image to be similar to the colors used for Alexander Hamilton in the original. The problems are that the picture is still labeled "Hamilton", and the background of the head is not right. The original has is a kind of squiggly matte background. An excellent version of the solution uses a similar background. I also changed the name below the head, and I applied a little "Artistic" / "Olifiy" fitering to to the head in this version:
So, how to do it?
First, note that this project might take a while. If you want to put it aside and come back later, you will want all the layer information to be saved. This means that you should save an .xcf file, using the "Save" command. Remember that an .xcf file includes the full Gimp environment. When you Export an image, on the other hand, you are only saving the final image and all the other information will be lost. (Remember to turn in the xcf file for this exercise.)
Start by opening the original ten-dollar bill in Gimp. The first task is to create a new layer, over the bill, containing the head that you want to use, including some of its background. One way to do that is to open the file that contains the head in Gimp. Then copy-and-paste a selection from that file into the image of the bill. Remember to use the "To New Layer" command to convert the floating layer into a new layer. (Alternatively, you can simply drag the file from the file system onto the bill in the Gimp window. This will add the entire image as a new layer, not a floating layer.)
Use the Move tool to drag the new layer into position over the ten-dollar bill. You will probably need to scale the head to fit the available space. You can scale the original image or scale the layer after you have pasted it. (There is a "Scale Layer" command in the "Layer" menu.) It might be easier to get the size right if you temprarily make the layer translucent, so that you can see the bill underneath.
You will also need to adjust the colors. Again, you can do that either before or after you paste the image. The image should be monotone, but with a slight green/yellow tint. In my project, I first used the "Desaturate" command in the "Color" menu, which converts the image to grayscale. (I found that it looked better with "Choose shade of gray based on" set to "Luminosity" in the Desaturate dialog.) I then used the "Color Balance" command in the "Color" menu to give the image the right tint. Hint: My color has just a bit of green and also a bit of red.
The next step is to cut a region out of the head image that just fits the space in the ten-dollar bill. Make an elliptical selection with the same shape as that space. This will be easiest if you make the pasted layer invisible so that you can see the bill. (In case you haven't already noticed, you can adjust the shape of an elliptical selection by dragging handles at the corners and along the edges. Use this feature to get the shape exactly right.) To avoid cutting out the name below the head, you can subtract a rectangular selection from the ellipse. To do that, hold down the control key while making the rectangular selection with the rectangle tool (or use the command key on a Mac).
Invert the selection, since you want to cut away the part of the image outside of the ellipse. Make sure that the pasted layer is active, and use the Cut command.
At this point, you should have the very minimal version of the exercise done. (Remember that the grade for "minimal" is C.) However, you really should try for an improved version by changing the background around the head and/or changing the text in the label below the image...
The Clone Tool is used to copy pixels from one image to another or from one point in an image to another point in the same image. (It looks like a rubber stamp in the Toolbox.) You can use it to copy the background that you need from the original ten-dollar bill image. To use it, first control-click (or command-click on Mac) the point in the image that you want to copy, then click or click-and-drag at the points where you want to copy it. It's usually best to use a brush in which all of the pixels are fully opaque. For this example, I got a good result by using a large brush and clicking a lot of points, rather than clicking-and-dragging.
It's a good idea to clone the background into a new layer, to make it easy to make several attempts to get it right. The problem is to limit the changes to the area surrounding the head. There are several ways to do that, but all of them probably involve making a selection around the region that you want to modify. (I used a combination of the color select tool and the Quick Mask, which allows you to modify a selection using painting tools. And feathering the selection just a bit can make the head and the background blend together a little better at their boundary.)
You can add text using the Text tool. The Text tool creates the text as a new layer. You will need to erase the original text from the ten-dollar bill, or add yet another layer to mask it.
When you finish, remember to save an xcf file, with a name such as ex8.xfc, to turn in.