Draw a nice scalebar

I didn't have MATLAB handy when I needed to draw a scalebar on an image,
so I converted https://github.com/habi/latex/blob/master/scalebar.m from
MATLAB to Python.
This script takes an input image and pixel size as input and calculates
a consistent scalebar on the image with TikZ. The user either has to
select a known length (-l parameter) or the script uses the full image
witdh (nice for tomographic slices). Afterwards it writes a
self-contained LaTeX file and compiles it, so you get both a .tex for
editing and .pdf for putting into a Keynote/PowerPoint presentation.