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

2019-06-14 01:44发布

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.

2条回答
Juvenile、少年°
2楼-- · 2019-06-14 02:02

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

查看更多
爷的心禁止访问
3楼-- · 2019-06-14 02:10

What possibilities are there to label the single images in the combined?

Iterate with a for loop.

for INDEX in {A,B,C}; do
    convert ${INDEX}.jpg labeled_${INDEX}.jpg
done

Is there an option to put the label not underneath the picture but eg in the upper left or lower right corner?

Try using the -annotate with -gravity

convert rose: -fill white \
        -gravity NorthWest -annotate +0+0 "A" \
        A.png

A rose

convert rose: -fill white \
        -gravity SouthEast -annotate +0+0 "B" \
        B.png

Rose B

查看更多
登录 后发表回答