SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2012-06-26 03:51:30

hhh
Caught in the Vortex
Registered: 2010-08-04
Posts: 2,346

Vector scan images with Inkscape

A quick How TO for creating a vector image from a raster image with Inkscape, with a few Inkscape basics covered too. My apologies to any graphic artists or mathematicians if I misuse any terminology or misconstrue anything. Here I'm assuming that you're using a standard keyboard plus 3-button-mouse setup. I used Inkscape 0.47 for this with it's default layout and toolbars, it's the version found in Squeeze. Thumbnails is this HOW TO can be clicked for the full size image.

A jpg, png or gif image is a raster image, also called a bitmap image, it is composed of dozens or hundreds of individual pixels of color. Enlarge a raster image and the pixels get larger too, turning into big squares of individual colors, and the file size will grow as well.

An svg, pdf, eps, or ai file is a vector image, it is composed of mathematical equations and algorithms. Enlarge a vector image and the math does the work. The image's resolution stays the same, curves don't pixelate, and the file size stays the same no matter how much you enlarge the original. Vectorizing is how those top-dollar design firms can produce a banner the size of a 5 story high exterior wall of a building and have the graphic stay crisp.

Inkscape, the OSS alternative to Adobe Illustrator, has Potrace embedded into it, a program which can trace raster images and export them in svg, pdf, eps or ai formats. Forum member el_koraco posted a screenshot where he had taken a full color image and processed it with GIMP to produce a 2-tone, black and white image, but the image pixelated badly in the transfer. I offered to fix it for him, this is how I did it.

Here's the original, reduced from 1300px wide to 500px wide (I've also converted all PNGs to JPG to save bandwidth). It doesn't matter that the original has been shrunk in this case, as we can enlarge the resulting vector image at the end with no loss in resolution...
tZWlkOQ

1) Begin! Select the image and open it with Inkscape, this will give you the image on a canvas, and the image will sit on an outlined part of the canvas that in Inkscape is called a page. Your final image will be the dimensions of your page when you export it, any part of the image that doesn't fit inside the page will be discarded. If you opened Inkscape first and then imported the image, just click the image with the selection tool (the arrow at the upper-left corner of the canvas), then go to File>Document Properties...>Fit page to selection.

TIP: Mouse wheel scroll up and down moves the canvas up and down, Shift+scroll moves the canvas left and right, Ctrl+scroll zooms the canvas under your mouse cursor in and out.

2) Vectorize! With you image selected (see step 1), go to Path>Trace Bitmap... and the 'Trace Bitmap' window will open. Move this to a corner of your screen, this window will stay on top of Inkscape's main window. For  this example, I used the 'Mode>Single scan>Brightness cutoff' settings. Click "Update" and you'll see a thumbnail preview of what you're about to do. With this image, the default 'Threshold' setting of .450 produced too much black and not enough white. Set the Threshold at .310 and click 'OK', and you'll see your new trace laid over the original. You can close the Trace window now.

3) Enlarge! Your new layer should already be selected, and if you hover your mouse over it a hand cursor should appear. Either left-click on the layer or use your keyboard's arrow keys and move it a little off to the side, so that part of the original image is accessible. Click the original so it's selected and hit Backspace on your keyboard to delete it, then select your vector scan again. At the top of the canvas are 4 fields labeled X, Y, W and H (X axis, Y axis, width, height) with a lock icon in between W and H and a dropdown menu of different measurements. Set the measurement to px, click the lock icon to keep width and height proportional and resize your layer by entering a number in the width field and hitting Enter, for el_koraco I needed it 1300px wide.

4) Export! Our Page is way too small now, if we export right now most of our image will be lost. Go to File>Document Properties...>Fit page to selection. Now go to File>Save As>Cairo PNG, and your scan is done! Inkscape doesn't export to jpg, but if you want a smaller file size you can convert your png to jpg using GIMP. Here's the result...
tZWlkYg

You can do much more by highlighting the layer as individual nodes, using the pointer in the left toolbar directly under the main selection tool. Click the vector layer with this tool and you'll see dozens of square points. Say you want to remove the white oval at the center-top of the layer, just select those nodes and delete them and the oval will disappear. Say there's a curve which bulges out too far, grab the curve in between two nodes with your mouse and pushing or pulling will make that curve shallower or fatter. You'll notice that my end result here is not exactly the same as the image I sent to el_koraco. Part of the difference was me editing nodes in Inkscape, the other part was me lightening Feist's cheeks in GIMP so her face had more uniform contrast, as Potrace's success is all about contrast.

Of course, the image doesn't have to be black and white, with your layer selected click one of the color icons at the bottom of the canvas and the black will change to that color. Or right-click the layer and choose Fill and Stroke>Fill and you can set Red, Green, Blue and Alpha levels.

Want to see your CPU pinned to 100% and Inkscape get all laggy? Instead of the Single Scan: Brightness trace, use Multiple Scan: Colors and set the number of scans to something higher than a dozen. I used this original...
tZWlkYw

... set the number of scans to 60 and unchecked Smooth and Remove background and ended up with this...
tZWlkZA


Happy Inkscaping!

Offline

Help fund CrunchBang, donate to the project!

#2 2012-06-26 09:20:03

el_koraco
#!/loony/bun
From: inside Ed
Registered: 2011-07-25
Posts: 4,749

Re: Vector scan images with Inkscape

Awesome!

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.

Debian Logo