Sometimes more elements find their way into a photograph than is really desirable, from a composition point of view. From doctored Soviet photos excising a deposed leader to modern fashion magazines' digital cosmetic surgery, it has long been convenient to seamlessly erase unwanted photographic truths.
The task of removing an unwanted element in a photo can be a long and tedious one. The texture resynthesizer plug-in for the GIMP goes a long way toward easing the task in many circumstances. In fact, using the associated Script-Fu script, the resynthesizer can often reduce the work to simply selecting the area to be reworked and telling the script to "go".
To follow this tutorial, you'll need to install the plug-in, which is available as the gimp-resynthesizer package in many Linux distribution repositories. Alternatively, the plug-in source files can be found at the Gimp Plugin Registry site: http://registry.gimp.org/node/25219
For an example to use in this tutorial, I offer my friend's picture of a warbler. It captures the warbler near her bird feeder. As you can see, a branch creates a distraction from the feathered subject of the photo. The resynthesizer plug-in will make short work of the unwanted limb.
Probably the first thing to know about the resynthesizer is that it takes its texture source from outside the selection area and applies it to the area within the selection. In other words, you only need to select the area you want removed and the resynthesizer will do the rest. Let's start by selecting the branch in our sample photo. With a simple shape like the branch, probably the easiest thing to do is create a path with the path tool, then create a selection from it. Feel free, however, to use the selection tool you feel is most appropriate in a given circumstance. The basic goal is a tight selection that encompasses all of the object you wish to eliminate.
The best way to start is to make a copy of the base image onto a fresh layer. The duplicate layer button on the Layers dialog window does the job nicely. The base image then makes a convenient reference, as well as a backup; just toggle visibility of the working layer to compare it to the original. Figure 2 illustrates the starting point with the duplicate layer.
The next step is to create a path with the paths tool, (shown selected in the toolbox in Fig. 2), that will become the template for the selection of the branch. Make sure your path completely surrounds the branch from one edge of the image to the other. Figure 3 illustrates the idea on the magnified image. Note that it isn't necessary to close the path, just make sure it starts and ends at the very edge of the image. (For reference, I started at the left edge with the top point and drew around to the bottom point on the left edge.)
Once you have a path around the object you wish to remove, simply choose the menu item, "Select - From Path", as illustrated in Figure 4, and a "crawling ants" selection outline will appear. You might wish to deselect the paths tool at this point, so the path becomes invisible and only the selection outline shows.
The path may come in handy later, though, so don't delete it from the Paths dialog window, shown in Figure 5. You may even want to give the path a descriptive name, as I have done in the illustration, by right clicking on the path's thumbnail in the window and choosing "Edit Path Attributes". A handy thing about a saved path is the ease with which it can be reused or edited to obtain a new selection.
With the selection made, we're ready to make the branch disappear. The menu location of the "Smart remove selection" script have proven migratory between versions 2.4 and 2.6. In 2.4, from the Script-Fu menu, select "Enhance", then "Smart remove selection"; in 2.6 you will find the script under "Filters - Enhance - Smart remove selection". In either case, you should be presented with the dialog pop-up shown in Figure 6.
The dialog pop-up provides the opportunity to set the radius around the selection that the resynthesizer looks to for composing the fill in for the removed object. For this image, the default 100 px is fine, though other images may be better served with another setting. In a moment we'll explore fine tuning this setting, but for now just click the "OK" button and sit back while the resynthesizer does its work. With the sample image the time to resynthesize will probably run 10 seconds or less, depending on your system's performance. With larger images the resynthesis time can be substantial. Anyway, the result, after choosing "Select - None" to deselect and eliminate the crawling ants, is shown in Figure 7. (The ants can be temporarily hobbled with Ctrl + T, but it's easy to forget you have an active selection.)
So, what if we want to try some other settings without disturbing the work we've done? What's the simplest way to do that? Well, remember that we left the original image untouched, on its own layer. We can use that and the path we made to experiment quickly and easily. Turn off visibility on the layer we just modified, (by clicking on the layer's eye icon), then make another duplicate layer from the original, Background layer as in Figure 8. In the figure I've renamed the first layer we modified, "First attempt", to avoid confusion. (Note that the layer "Background Copy #1" is selected in the Layers dialog window. One of the keys to working with layers is remembering to make sure you have the layer you want to work on selected and have no visible layers above, obscuring your changes. If you try something and it doesn't appear to have an effect, look here first.)
Now, simply use "Select - From Path" to select the branch on the new layer. This easy reuse is why we kept the path we made, earlier. Next, reapply the Smart remove selection script again, as before. When you are presented with the dialog pop-up, you can change the radius the tool uses. As you can see, once you have the path set, it is remarkably easy to revisit your work and try different settings by simply duplicating the original layer and applying the existing path to create a selection on the new layer. (Note that if you use a tool other than the paths tool to create your original selection, you can always create a path from the selection with "Select - To Path" from the menu.)
As might be obvious, the resynthesizer's smart removal feature works best when the background is fairly consistent and lacking in intricate detail. Sometimes it works better to break the object into sections for removal and use the resynthesizer directly, instead of through the "Smart remove selection" script. This offers more control over how the resynthesizer creates the replacement texture. You can find the resynthesizer in "Filters - Map - Resynthesize".
The resynthesizer plug-in can perform a variety of other functions besides removing unwanted objects. Among its features are the abilities to produce seamless textures for backgrounds or to apply textures from one image to another. On your Linux system, you can find a bit more information on the resynthesizer in the file: /usr/share/doc/gimp-resynthesizer/README.gz.