Whiteboard Diagrams as PDFs

Need a quick diagram for the paper you’re working on? Instead of this:

\begin{figure}
\vspace{0.5in}
Remember to put a diagram here!
\vspace{0.5in}
\caption{The to-be-written awesome caption will go here.}
\label{fig:now-its-all-clear}
\end{figure}

what if you could quickly turn a whiteboard sketch into a diagram suitable for use as a draft — and maybe even for use in a camera-ready, depending upon your drawing skills — in your paper?

I find drafting diagrams on the whiteboard is much faster than trying to do it in PowerPoint, OmniGraffle, or the like. Dan Roam’s non-technical but useful book The Back of the Napkin might help convince you of this, if you aren’t too averse to what I think of as business-targeted self-help books. Randall Munroe’s “what if?” posts are an excellent showcase for the explanatory power of simple line drawings. Who knows? You might like your hand-drawn diagram so much that you use it as-is, and don’t end up recreating it in Powerpoint.

But then how do you get it into a nice vector format for use in LaTeX or the like? Pull out your smartphone, take a picture of the whiteboard, and put it on your computer. You can use various programs to make this easier, like the Camera Upload feature in Dropbox’s phone app.

Smartphones usually produce JPEGs, which aren’t the ideal image format for diagrams, particularly diagrams that should have the feel of vector, rather than raster, graphics. I use several open source tools to quickly convert a JPEG like this:

a picture of a drawing of a drawing

into a small, scalable vector diagram like this:

a drawing of a drawing

It’s a multi-step process. First I crop and threshold the image into a bitmap using Gimp, and then I vectorize it using potrace. Specifically:

  1. Crop, threshold, and make a bitmap:
    • Load the JPEG in Gimp.
    • Select the area you want to crop.
    • Crop using ImageCrop to Selection.
    • Convert to a bitmap using ImageModeIndexed.
    • (Optional) Scale the image using ImageScale Image... to about 1,000 pixels or so in the shorter dimension, preserving the aspect ratio. This step isn’t necessary, but might help potrace if you have a particularly high-resolution camera on your phone.
    • I get best results if I use Generate optimum palette with two colors, rather than using Use black and white (1-bit) palette. You’d think they’d be identical, but in my very limited testing, they’re not. Your results may vary.
    • Export to a bitmap format that potrace can understand. Use FileExport..., and save as a PBM.
  2. Use potrace to convert from a bitmap to a vector format:
    • To make a PDF, try potrace -b pdf -o file.pdf -t 10 file.pbm. You may want to play with the potrace algorithm’s options (see the man page); the -t n option suppresses speckles of up to n pixels, which I find useful in removing stray whiteboard marks; calibrate n to the size of the image and the dirtiness of your whiteboard.
    • You can use -b svg to create SVG files, which can be rendered by most web browers. That’s where the preceding image came from.

There are many ways to tweak this process. Use ImageMagick or GraphicsMagick instead of Gimp if you want to do it all at the command line, or try Inkscape’s integrated potrace functionality if you want to do it all in a GUI.

Happy drawing!

Marc Liberatore
Marc Liberatore
Senior Teaching Faculty

My research interests include anonymity systems, file and network forensics, and computer science pedagogy.