May 18, 2005

Convert your bitmapped image to vector graphics format

Peter Selinger: potrace. This is the best way I've found so far to convert bitmapped images to vector format. I needed to convert a school seal that was only downloadable as a bitmapped file to both eps and pdf files for inclusion in my dissertation, for the best print quality. Here the steps I took:

1. Converted the bmp file to svg format for editing in inkscape: potrace -o outputfilename.svg -b svg inputfilename.bmp
2. I then opened up the svg file in inkscape and edited the canvas size to suit my needs. I also wanted to change the opacity of the image (so that I could use it as a watermark), but for some reason, opacity and changes in the alpha channel is not retained in eps format saved in inkscape---I had to find another way using xfig.
3. After editing in inkscape, I "Saved as..." an eps file. I converted the eps file to fig format using pstoedit: pstoedit -f xfig inputfilename.eps outputfilename.fig.
4. I opened up the resulting fig file in xfig and changed the properties of each polygon block by choosing the "Edit" button. In the edit mode, each block was methodically chosen and the fill intensity of each block was changed from 100% to 15% (the opacity I wanted).
5. In xfig, the pdf and eps files for the image I was working on was created with the "Export" option under the File menu.

The resultant pdf and eps was used for pdflatex and latex forms of my dissertation respectively.
Potrace works well for bitmapped images that are large and are generally black and white. If there is a lot of gray in the image, it will most likely be lost since potrace will only trace lines above a certain threshold of intensity. If you want to have a better trace from potrace from a non-black and white bitmapped image, you can try the following:

1. Open up the image in gimp.
2. Resize the image to a very large size. I like to use at least a 1600 px wide image. You will most likely get a highly pixelated image.
3. Perform a series of contrast changes, blurs (under filter menu), and unsharp masks (filter menu) to smooth out the pixels and to darken the grays. You can play around with the sharp filter menu options to get the image just right.
4. Once you get the image set at the right contrast in black and white (some gray is ok, but will be lost in potrace), save the image in gimp as a bmp or ppm file.
5. Convert the bmp or ppm file using potrace to svg: potrace -o outputfilename.svg -b svg inputfilename.bmp
6. Open up the svg file in inkscape and have fun ungrouping and editing the image to your liking. You can save as any format you want from here: eps, ps, or even back to bitmap.

Posted by johnvu at May 18, 2005 02:51 PM
Comments
Post a comment