Annotating micrographs with a scale bar

Bastian Asmus

This post describes three of the many possible ways of annotating micrographs with a scale bar: manually, semi-manually and fully automated. Any meaningful micrograph needs a scale as a means of informing us about the size of the documented microscopic structutres. There are two ways possible: Either use the caption to tell us the image width, or annotate the image with a scale bar. The  left image (click!) informs us about the image in an unobtrusive bar at the bottom of the image, the right image shows the solution with the scale bar.


1. Annotating micrographs manually
2. Making scale bars – Using Scientific Image manipulation software ImageJ
3. Annotating micrographs using meta tags and a simple shell script

1. Annotating micrographs manually

Is is any good to note the magnification in your records? The answer is no, because the magnification relates to the image you see through your ocular lenses.

  1. Take a micrograph of a stage micrometer for every objective lens you intend to use. You need to do this only once.

    Image of stage micrometer

    Stage micrometer for reflected light microscopy

  2. Calculate the pixel aspect ratio: image width in pixels divided section width in micrometers (µm). This ratio may be used to calculate the lenght of the scale bar. Exmaple: the image below is 3245 pixels wide and it shows a section of  the stage micrometers that is 650 µm wide: 3245 pixels / 620 µm = 4,99 pixels/µm

    stage micrometer micrograph

    The micrograph of the stage micrometer shows this image to be 620 µm wide. This can be used to work out the pixel aspect ratio.

  3. Calculate the length of the scale bar in pixel. Let us say the scale bar should show us a lenght of 200 µm, then we need to draw a line of 200 µm * 4.99 pixels/µm = 998 pixel.
  4. Draw the scale bar. You can use any graphic software for this. I used Inkscape. Draw a line with the Bézier tool and add some text. Use the align menu to justify text and line.

    Drawing the scale bar in Inkscae

    In Inkscape make sure you change units to pixel (px). Then you can select the Bézier tool (shortcut: B) to draw a straight line. Change tools to selection tool (F1) and specify the length and thickness of the line.

  5. Export scale bar as png graphic. Select all (Ctrl + A), hit the export button, select  Selection button, make sure  Bitmap size is set to the correct pixel size, in our case to 998 pixels


    Make sure to use the selection button (here: called Auswahl). Set bitmap size in accordace with your calculated scale bar.

  6. In GIMP open micrograph import scale bar and place it

Of course you may also draw a proper scale bar in Inkscape and scale to the dimensions you require. If you do one or two mircographs this approach is fine, but if you have to annoate  tens or hundreds of micrographs with scale bars, this becomes rather tedious.

2. Making scale bars – Using Scientific Image manipulation software ImageJ

You may use the programme ImageJ to speed up things quite a bit, but it still rerquires a manual work.

1. Choose [set scale] form the  [Analyze] menu



2. Enter details, such as the known image width in µm and in pixelEnter details of the scale bar properties

3. Select [Scale Bar…] from [Tools] submenu in the [Analyze] menu

Menu for setting the scale bar

4. Specify length, colour and placement of the scale bar

Specify the appearance of the scale bar

3. Annotating micrographs using meta tags and a simple shell script

Thanks to the help with regular expressions of Johannes Kutterer from I finally sat down and wrote a shell script that does the annotating by itself. The script is based on the idea to store all relevant information within the image itself. To this end I use meta data that can be embedded into the digital image.

Screenshot of digiKam

DigiKam offers a large range of professional solutions, is under constant development and is an excellent editor for meta data.

All that is required for the script to work is that the width of the field of view of the image is stored within the meta data keywords. I am using EXIF, XMP and IPTC meta data formats, which can easily be added, edited and deleted with digiKam.


O.k., what does this script do?


  1. the script is bash shell script called from the command line
  2. navigate into the folder with your micrographs
  3. the script can be used with default values (white scale bar on black background, files with the extension JPG) use_scalebars3use_scalebars3
  4. you may also specify the file extension and the colour of scale bar and background
  5. the script does not alter the original files, instead it creates a folder called ‘annotated’ and places the annotated copies therein
  6. that’s it


    Micrograph showing a section  in cross polarised light. Scale bar was added by the shell script above.

O.k, but what does the script do?

The scale bar annotation script reads meta data from the micrographs and uses that data to annotate the micrograph with a scale bar. Read more on how relevant metadata can be embedded in your micrographs in this post.

The script reqires both Imagemagick and Exiftool to be installed on your system. If you like what you read here you are welcome to leave a comment and let me know.

3 Responses to “Annotating micrographs with a scale bar”

  • quantify the concentration - scientific image manipulation | archaeometallurgy Says:

    […] it can calculate area and pixel value statistics of user-defined selections. It allows the user to apply a scale to an image and can measure distances and angles as well. It is also used to cross check results of various […]

  • Sebastien AZE Says:


    Thank you for your post about the bash script for adding a scalebar to micrographs, but… I cannot make it work: I have error messages such as:
    “ ligne 8: $’\r’ : commande introuvable
    ” (means: “unknown command”)

    Do you have any idea of what is wrong?

    I use it on a Linux Mint Debian, kernel 3.11-2-amd64

    Thanks in advance for your reply, if you have time…

    Sebastien from Marseille, France

    • Bastian Asmus Says:

      Dear Sebastien,
      it turns out that I introduced a minor error in the script, whilst editing out some typos… Sorry for that. I did correct it in the above code and sent you a corrected version as well. Let us know if it works.


Leave a Reply