Computer Graphics

Basics: Paths

The task of this tutorial is the same as the previous: Mask out the background of the original photo and replace the background with a different one. However, the situation is a bit different than before. We can not use the fuzzy select tool because the border between the object and its background is not clear enough for the fuzzy select tool.

Download and open this image:

1. Fuzzy selection doesn't work

Even if you play with the threshold of the Fuzzy select tool, you won't get good results. The selection will either contain too much or too little or will have weird borderline:

Does this mean we are back to painting the mask manually? Not exactly. The bottle has a nice well defined smooth shape and we will use paths to define a selection that matches the bottle shape.

2. Working with paths

A path is a tool of vector graphics. Raster editors such as GIMP or Photoshop use it to create an editable path for selection or for drawing shapes (stroking).

The path tool is located here:

By default, first click creates a new path and each following click creates new points on the path.

Click and dragging and existing point will move the point.

Click and dragging and existing line will turn the line into a curve and move it.

When you hold CTRL, you can add new points on an existing line by clicking the line.

When you hold CTRL+SHIFT, you can delete existing points.

3. Rough outline around the bottle

Now pick the path tool and create several points around the bottle. When you want to connect the last point to the first point and close the curve, press and hold CTRL. The cursor changes and you can click on the first point. This will close the path:

4. Refine the shape

 Now zoom in and refine the shape by adjusting the curves:

Try to fit the shape to the bottle's outline. This is the intermediate result:

5. Convert the shape to selection

Every shape can be used to create a selection. We will now use our shape to select the area inside it - the area occupied by the bottle. There are two ways to do it. Either do it directly in the tool options panel or in the Paths panel in top right.

 

This will create a selection in the shape of the path:

This selection can now be used to copy the bottle and paste it as a new layer without the background. Do it and hide the original layer. This should be your result:

6. Editing the shape

If you are not satisfied with the result, you can get back to the path by clicking on it in the Paths panel which is a tab next to the Layers panel. You can edit the points and then redo the Step 5.