How to create detailed vector traces in Inkscape

Moderate GIMP Inkscape Tutorial


I recently read a great tutorial over at Paul Hill's Creative PSD blog in which he demonstrates a technique for using Adobe Illustrator to achieve a detailed vector trace of a source photograph of a tree. My first thought when reading really good tutorials like this is "How would you do it using Open Source software?", and here is my interpretation of Paul's method using Inkscape and GIMP.

There are a few techniques for doing this, including some quick-and-dirty tactics which will get you a good outcome faster than I'll show you here, but what I describe is a solid method and should get you a useable result for a variety of images.

Although the end goal is to get an accurate vector object from Inkscape, a lot of the up-front work is done in GIMP, to maximise our chances of getting a faithful reproduction of the tree outline, including the all-important internal spaces which define the shape. Again, this is a practice which can be applied to a range of images you choose, and isn't constrained to this tutorial. Hey, I'm trying to equip you with life skills, here.

Let's take a look at what we'll be producing at the end of this tutorial.

A leafy tree silhouette created in Inkscape


Tall Oak Tree image Credit: Philip Halling; Wikimedia Commons.

Skills you'll be developing in this tutorial

Step 1 - Find a tree photo and adjust the contrast in GIMP

It's important to realise that there are limitations to any software's Bitmap Trace tool, and certain photos will be more difficult to achieve a good result from than others. In general, if you have the opportunity to use a photo where your subject and its background have a reasonable degree of separation in either colour or brightness, you should opt for that one.

Examples of good and poor photo choices

So with that in mind, locate the tree photo listed in the Resources section, and open it in GIMP using File --> Open or by dragging into one of GIMP's windows straight from your download area. We'll use GIMP to establish the right conditions for Inkscape's trace tool to do its job well.

Open the tree image in GIMP

Locate the Layers panel (Ctrl and L to make it appear). Duplicate the image layer using Ctrl, Shift and D on the keyboard, or by clicking the Duplicate Layer button at the bottom of the panel.

We're going to use this layer copy later, so hide it for the time-being by clicking the eye icon to make it invisible for now.

Hide the tree layer copy

Next, make sure you've got the original layer activated by clicking on it in the Layers panel so it's highlighted. Then select Colors --> Brightness-Contrast from the menus and, in the dialog box that appears, move both the sliders to the right to boost the contrast of the photo quite a bit.

This may result in your photograph becoming 'false' in the sense of true colours being spoiled, but what we're looking to do is to establish good, clear separation between the tree and its background, without disturbing the clarity of the edges of the outline and inner spaces.

Boost the contrast significantly in GIMP

Step 2 - Use a copy of the image to create a layer mask

Make the copy of your original image visible again by clicking the space where the eye icon was, and click the layer name itself to make it the active one, then click Colors --> Desaturate and select Luminosity from the three radio button options.

Desaturate the top layer copy

Now we need to enhance the contrast on this layer even more than before, to create a very strong black-and-white version of the image. We will use the result as a Mask for our initial cut-out.

The most reliable way to do this is to use the Levels feature, which is located under the Colors --> Levels menu. Drag the mid-point and white-point arrows down to around half way across the Input Levels range. You can then move the black-point arrow right slightly.

You'll see that almost all of the grey tones become either clearly white or clearly black, depending on which side of the mid-point they fall. By closing up the levels, we've created a sharply-contrasted monochrome version of the tree, which we'll use as a mask in the next step.

Use a Levels adjustment to create a sharp cutoff between white and black

Copy the pixels in this layer with Ctrl and C (or Edit --> Copy), then hide the layer so that the colour version is visible again. Right-click on the visible layer in the Layers panel and select Add Layer Mask.

Add a mask to the image layer

Now Paste (Ctrl and V) the black and white image of the tree into this Layer Mask (as you've just added the mask, it will be active by default). You'll see a new, temporary layer appear at the top of the layer stack. Press Ctrl and H or right-click and select Anchor Layer to anchor the pasted image to the Layer Mask area.

Paste the copied pixels into the layer mask and anchor it

Whoa! That doesn't look right at all. But don't worry: it's just the inverse of the cut-out we need, according to the rules of GIMP's layer masks. With masks, black pixels are like a piece of opaque card laid over a painting, and white ones are like holes cut out of it which allow us to see the picture underneath.

Therefore, if we swap the blacks and whites we'll have what we're after. So, with the Layer Mask still active, hit the Colors menu and select Invert to do exactly that.

Invert the layer mask's colours to get the right result

Ah-ha! Much more like it and, as you can see, there's just a little bit of work left to do to get a great cut-out ready to be traced.

Pick a soft brush and paint (keyboard P to activate the Paintbrush tool) the layer mask with some more black pixels to remove the areas which, because they had little or no contrast against the tree's colours, are still present. I chose a circle brush with a Hardness of 50%, and a size of around 30 pixels.

Zoom into the areas you need to and brush around until the excess areas become transparent around the central subject of our tree.

Grab a soft paintbrush and erase unwanted image areas

Usefully, because we're not painting on the image itself or deleting bits of it, we can always go back and improve the selection by changing the paint colour and brushing over an area again. Keep brushing until you've isolated the tree nicely from all the background regions; lower the size slightly for fiddly regions and raise it again when you're in the clear and need to brush large areas quickly.

Complete the opacity mask with more brushing

When this is done, activate the Crop tool (Shift and C on the keyboard) and drag a crop area around the tree, just so we can prune off (ha!) all the unneeded blank space around the borders. Press Enter or click inside the crop area with the mouse to complete the crop.

Create a crop area around the tree and crop the image

That's looking like something we can use, so Export the image with Ctrl, Shift and E or File --> Export and save the output file to a memorable location in PNG format. Remember to add the .PNG extension to tell GIMP we want to keep that transparent background. You can accept the default settings in the PNG export dialog box that pops up after the Export Image one closes.

Export the PNG from GIMP to use in Inkscape

After that, it's time to move over to Inkscape to finish the job.

Step 3 - Import the photo to Inkscape and trace the bitmap image

Open up Inkscape and bring up the Import Image dialog box with Ctrl and I or File --> Import. Locate the PNG you exported from GIMP and click OK. In the next box that appears, choose Link - this will enable you to keep GIMP open in the background, make changes to the photo and re-export, then see the image update in-situ within Inkscape straight away, which is obviously very useful.

Import the image to Inkscape's window

You should see your roughly-cut out photo on the page. With it selected, open up the Trace Bitmap dialog box with Shift, Alt and B on the keyboard, or Path --> Trace Bitmap in the menus. You'll see the box pop up with a range of settings and options split across two tabs. I'll go through what they mean below.

Head to the Trace Bitmap dialog box with the photo selected

On the first tab, Brightness Cutoff is the Mode we will use in this instance. It instructs the trace process to look for the edges of the tree where pixels are darker than a certain threshold; that's why we picked this image originally and why we edited it in GIMP first. A high number in the box gives you a shape which covers most of the non-white areas, whereas a lower setting only traces the very darkest regions and leaves the rest alone.

Some examples of the Brightness Cutoff trace in action

You can see the effect that changing the Brightness Cutoff threshold value has, and that's the majority of the work, to be honest, but there are some useful settings on the Options tab of the Trace Bitmap dialog box that are worth some attention, too.

The Trace Bitmap options panel has some useful settings

The settings I show you should be used as a guide, and you'll need to use your own judgement as to what looks best according to your own requirements. The Brightness Cutoff value I settled on in the end was 0.420.

Try different settings to get a good trace result

Once you've got your trace, it's worth looking around for any parts of the result that need some extra attention. For example in mine, I've got a few regions that have been traced but fall outside the main tree shape, which looks a bit untidy.

Simply activate Inkscape's Node tool, Zoom in substantially so you can work up close, and drag a selection around the offending floaters. Alternatively, click on them in turn while holding down the Shift key if a rubber band selection isn't practical. Then hit the Delete key to remove them from the trace. Repeat until you've got a clean shape without artefacts.

Use the Node tool to select and remove detached shapes which have been traced

And there you are - a totally vector, monochrome trace of your complicated source tree image. By all means experiment with the steps in this process. For example, using Multiple scans of the source image's Colours can produce a nice effect.

Experiment with other trace options to explore the possibilities

You might also like to edit the trace shape slightly, to elongate the tree trunk and make it appear less stumpy and more elegant. This can be done with the Node tool like before, but instead of deleting the nodes, I selected the nodes at the bottom of the trunk and dragged them downwards slightly.

You can use the Node tool again to sculpt your final result

In isolation, we should have something like:

A leafy tree silhouette created in Inkscape

That's not looking too bad at all - I can now take this tree silhouette and incorporate it into a project where it's needed, scaling it to any size I like without losing the detail because it's a vector image.

Once saved you can use the vector tree in other projects

And if you want to know how to use your silhouette vector to make something like that, well, you'll just have to stay tuned and see what I've got in store for you soon. :-)

Has this tutorial left you with a great impression, or did it just disappear without a trace? Let me know by leaving a comment in the section below.

Mark is the Editor and owner of Designmark Graphics Ltd. Publishing tutorial articles and guides for Inkscape and the GIMP, this blog aims to boost the profile of these Open Source graphics applications and showcase what they are capable of.

comments powered by Disqus

Connect with me

I'm on a range of social channels and, to get alerts as soon as new tutorials are published, subscribe to the RSS feed using the link below.

Search the site

Search the site for a topic or tutorial subject using the search box below:

What's this blog about?

The Designmark blog is the best online resource for Open Source Graphics software tutorials, showing you how to produce quality graphics in Inkscape and the GIMP. You can find out more about how this blog came to be and what's going on behind the scenes in this article.

Who's in charge here?

That would be me, Mark. You can learn more about me, my background and the design work I do on .

Things that built this blog