Vectorizing an image using open source tools (Inkscape and GIMP)

This is a common enough task, and there are a few blog entries out there on how to vectorize an image, but most of them make assumptions about your file, or take way too long to get to the point!

Vectoring an un-vectored (or rasterized) image involves converting an image into a set of 'line' instructions, contained in an .svg format file. These files let you resize your image to any size, without losing any definition. They're a must for things like logo files.

I had the opportunity to vectorize a logo image recently (the original vectored file had been lost), so after much trial and error, worked out the most important steps and have documented them here briefly in point form so you can get going as fast as possible.

We're going to be using GIMP for image processing (creating a high contrast image), and Inkscape for vectorizing and fine-tuned editing of the paths. Note that you can't do vector editing of an .svg file in GIMP: that's what Inkscape is for. Similarly, you can't really edit images in Inkscape - things like filtering, colour adjustment and contrast settings are best done in GIMP. GIMP also won't let you modify the 'code' (vectors) in an .svg file: it's an image oriented system. The principles (and almost the menu options too) are the same if you're using their equivalent commercial tools (Photoshop and Illustrator).

1)  Convert image to high-contrast

Ensure your image has enough contrast over the elements you want to vectorize. Without enough contrast, GIMP is going to have a hard time working out the different objects in your image.

The most commonly recommended way to do increase your contrast (and thus the success of your path definitions) is to convert your image to black and white, so you end up with a high contrast schematic-style image that works best with Inkscape's path functions. Whatever you use, make sure you start with an image that will allow for easy detection of image component borders.

2)  Open file in Inkscape

Open your high-contrast file in Inkscape, then select the entire contents of the file (Command/Ctrl-A).

3) Convert image to a series of paths

Click menu option 'Paths - Trace Bitmap' and play with the settings in the popup window. There's a balance to be had here: between over-complex vector definition that is accurate but bulky, and over-simplified vectoring that misses the more subtle aspects of your image file.

4) 'Clean up' your vector paths


This step is most important.

a) Excess points on straight lines

You'll often find an excess number of path points in your automatically vectorized image. An example here would be a vertical line that borders say a character (like the letter L') containing unnecessary path points down its vertical edge. For a straight vertical line, you only need 2 path points, and this is the goal with the editing described next.
To clean these up, click the middle, unwanted point in your line, then click the path point delete button. Now edit your path Bézier curves, dragging them back to the corner point, until the context-text reads 'collapse point to edge'. For lines with simple 90 degree connections, you'll have successfully simplified the path - which you can see in the XML box on the right (find this in the View menu). Do this throughout your image, until all straight lines (at any angle) are now made up of just 2 path points, with no Bézier curves.

b) Fix letters made up of multiple paths

Letters like 'A' and 'B' contain central paths (for the 'holes') that are stored as separate paths - this means that a letter like 'B' is made up of 3 paths. You can convert this back to one path by selecting the outline path, then one of the 'hole' paths, and then clicking 'Path - Difference'. Repeat the same step for the second 'hole' in B. You'll now have one (more complex) path that represents the entire letter, which makes more sense.

5) Select fill colouring for path objects

In the path editing window, you can choose a line width, line color and fill color. In most cases you will want no border for your path objects, so click the 'X' icon for no border color (the line width is now unused, but should be set to 0.00 in any case). Choose the right fill color for your path object - you can use hex notation for this, but note that Inkscape also uses an alpha setting as the last 2 digits (ie. 6 digits for color, and 2 for alpha - or transparency). An orange colour I recently used was therefore:

#F15D22FF
#F15D22 is a type of orange, and FF means no transparecy is applied ie. you get the full colour.

6) Arrange your paths and layers

The default setting for 'Paths - Trace Bitmap' provides no logical ordering of your new paths. It usually makes sense to break your image up into logical layers (e.g. one for a logo, one for some text etc.). To do this, first create your new layers (in the layer menu).
You will also want to see the Layers window while you're doing this: click 'Layers - Layers...' to see this window. Now select multiple path objects that go together (hold down shift as you click on the object), then right click and select 'Move to Layer' and choose your layer.
Note that in Inkscape, editing directly in the XML editor window doesn't seem to retain the grouping into layers between saves - you need to create your layers using the menu option, not the XML editor.
Now you can re-order your paths. In the XML Editor window (available by clicking 'Edit - XML Editor'), drag and drop your paths till they make some logical sense (eg. put all the letters for one word in sequence).

7) Re-label your path id's.

It's a good idea to also re-label your path ids away from the default (path_001) to something more sensible eg. path_logo_part_01. You can do this in the XML Editor.

8) Save your .svg file

Inkscape works on .svg files. Save your file, and you can now open it for final image creation in your image software (GIMP or Photoshop. You'll be able to make your image file as large as you want without loss of definition because you're now working on an .svg vectored file, rather than the original rastered version (.png, or .jpg).

Comments

  1. Thanks for your tips on converting vector art images in a very simple way. Your post is best in all about raster to vector conversion. Thanks.

    ReplyDelete
  2. My pleasure @Vector Art and thanks for the comment. Converting to vectors is a much under-utilized skill, but the efficiency, smaller-size and accuracy are well worth it if your original graphic can take it, and it leaves you with a 100% scalable image. Hence the desirability of doing it for logos and the like!

    ReplyDelete

Post a Comment