potrace: Transform bitmap images into vector graphics
May 19th, 2008 edited by TinchoArticle submitted by András Horváth. Guess what? We still need you to submit good articles about software you like!
You can face the task sometimes that you need a high resolution material from a particular image. Most probably when you’re a graphic designer (or even a tattoo artist), you might want to have a good quality result from a low resolution image that you can magnify no matter how much, it will give you smooth edges in high quality.
For this, you have the following possibility without a trace program: using a pixel graphic software like Gimp, you can resize the image with the best resampling method and apply a selective blur filter on it. Most of the times this doesn’t give the necessary quality.
There is a small but powerful utility called potrace
developed by Peter Selinger, a mathematics professor at the Dalhousie University.
With a trace program like potrace
, all you have to do is to give the image as an input, and there you have the result in the standard SVG format. potrace
can produce even PDF format as an output.
Command-line example:
$ potrace -s image.bmp
With this process, the program transforms the images’ pixels into filled curves that have infinite resolution with smooth lines at any zoom.
In my personal experience while working as a graphic designer, potrace
gave me very good results to many input images. Compared to other high expensive proprietary software, when the input image had sharp endings, potrace
gave sharp edges in the result and other programs gave bad results, curving the edges. That needed a lot of manual correction.
Pros (compared to other programs):
- Very good results
- Pretty fast
- Can be easily run from a command-line
- Can be used from the Inkscape open-source vector graphics software (Path / Trace Bitmap menu or Shift+Alt+B)
Cons:
- Only 2 colors output (Black & White), no colored process is available yet
potrace
does not support PNG images as an input (though images can be converted easily from PNG with a whole variety of free programs)
This is an example found in the homepage, you can see the original bitmap and the vectorised image:
The package has been available both in Debian and Ubuntu since a long time ago.
Related links:
May 19th, 2008 at 5:27 am
> images can be converted easily from PNG with a whole variety of free programs
Yeah, for example
cat inputfile.png | pngtopnm | potrace -s > outfile.svg
The netpbm package contains many such “[someformat]topnm” programs.
May 19th, 2008 at 6:27 am
Impressive!
May 19th, 2008 at 8:42 am
Excellent !
Note that you can process colored images with inkscape and the “multi passes” option in the (Path / Trace Bitmap) menu.
Thanks !
N.
May 19th, 2008 at 9:01 am
doesn’t autotrace support colors?
May 19th, 2008 at 12:22 pm
“potrace”
cool! a marijuana-themed racing game.
oh, wait..
May 19th, 2008 at 6:17 pm
Autotrace does indeed support colours. However, I wanted to convert a stained-glass window into SVG and was more impressed with an online web-based vectorizer. A comparison of this potrace and autotrace, with regards to ease of use and quality of output, would be quite valuable - especially for those of us who don’t know much about either beyond the occasional use.
May 20th, 2008 at 8:39 pm
cool! to convert image from other format you may use command tool “convert” from imagemagic (http://www.imagemagick.org). Example: convert someimage.xxx someimage.bmp create someimage.bmp from someimage.xxx, where someimage.xxx may be in various format.
Thanks.
May 23rd, 2008 at 6:40 pm
I just upgraded my Inkscape from 0.45-1 to 0.46 (Debian/Lenny) and noticed that the built-in potrace can create color outputs too here ;)
May 25th, 2008 at 3:19 pm
potrace alone gave me the perfect .svg, except it’s black and white. I couldn’t find a colour option in it, and the built-in one in Inkscape didn’t really work. Or well, I couldn’t figure out how to use it :(
May 28th, 2008 at 11:34 am
And if you don’t like command line you sould use potracegui :)