Search

potrace: Transform bitmap images into vector graphics

May 19th, 2008 edited by Tincho

Article 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:

Original bitmap potrace output

The package has been available both in Debian and Ubuntu since a long time ago.

Related links:

http://en.wikipedia.org/wiki/Potrace

http://wiki.inkscape.org/wiki/index.php/Potrace

Posted in Debian, Ubuntu |

10 Responses

  1. rm Says:

    > 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.

  2. EvilDead Says:

    Impressive!

  3. N. Nobelis Says:

    Excellent !

    Note that you can process colored images with inkscape and the “multi passes” option in the (Path / Trace Bitmap) menu.

    Thanks !

    N.

  4. gurkan Says:

    doesn’t autotrace support colors?

  5. bart9h Says:

    “potrace”

    cool! a marijuana-themed racing game.

    oh, wait..

  6. Tim Says:

    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.

  7. valfrom Says:

    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.

  8. log69 Says:

    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 ;)

  9. Vadim P. Says:

    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 :(

  10. macsim Says:

    And if you don’t like command line you sould use potracegui :)