imageimagemagickmontage

Numbering/Labeling images (eg 1,2,3 or A,B,C) with ImageMagick montage


I'm using

montage *.tif output.tif

to combine several images to one. I would now like them to be numbered (sometimes 1,2,3 …; somtimes A,B,C …) What possibilities are there to label the single images in the combined? Is there an option to put the label not underneath the picture but eg in the upper left or lower right corner?

Unfortunately I could't really figure out how to use the -label command to achieve that. Thanks for any suggestions.


Solution

  • If you want to invest a little more effort you can have more control. If you do it like this, you can label the images "on-the-fly" as you montage them rather than having to save them all labelled and then montage them. You can also control the width, in terms of number of images per line, more easily:

    #!/bin/bash
    number=0
    for f in *.tif; do
       convert "$f" -gravity northwest -annotate +0+0 "$number" miff:-
       ((number++))
    done | montage -tile x3 - result.png
    

    enter image description here

    It takes advantage of ImageMagick miff format, which means Multiple Image File Format, to concatenate all the output images and send them into the stdin of the montage command.

    Or, you can change the script like this:

    #!/bin/bash
    number=0
    for f in *.tif; do
       convert "$f" -gravity northwest -fill white -annotate +0+0 "$number" miff:-
       ((number++))
    done | montage -tile 2x - result.png
    

    to get

    enter image description here

    Or maybe this...

    #!/bin/bash
    number=0
    for f in *.tif; do
       convert "$f" -gravity northwest -background gray90 label:"$number" -composite miff:-
       ((number++))
    done | montage -tile 2x - result.png
    

    enter image description here

    Or with letters...

    #!/bin/bash
    number=0
    letters="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    for f in *.tif; do
       label=${letters:number:1}
       convert "$f" -gravity northwest -background gray90 label:"$label" -composite miff:-
       ((number++))
    done | montage -tile 2x - result.png
    

    enter image description here