How can I make a montage with ImageMagick from images with different size and aspect ratio?
Asked Answered
B

1

10

I have a lot of images, different sizes and aspect ratios. Is it possible to make a montage of them? I mean to optimally arrange them in rows after I set a common height for the images which build up a common row. Images aspect ratios aren't allowed to modify of course, and none of the images are allowed to omit from the final montage nor duplication.

The height of picture rows in the montage usually aren't equal, but their values should be kept in a minimal range (in statistical sense) or in other words: standard deviation from the mean value of the row heights must be minimized.

Desired width and height of the montage are given (a.)

Or the width and an allowed ratio range (or equivalently height range) is given (b.), for example width must be 1024 pixel, height must be so that w/h < 0.9 and w/h > 0.8

1.) Images must be packed in the montage in their initial fixed order. In this case one must find the images after what a new image row should be started in the montage (easy).

2.) Order of images is allowed to be altered. In this case one must find a permutation which lead to a minimalization of the standard deviation of the final row heights when each image is packed into the montage (hard).

For example:

enter image description here

enter image description here

Braynard answered 12/2, 2014 at 9:30 Comment(3)
If it is a "once in a lifetime" task I would recommend one of the many online services. They provide creative ways of compiling images. ImageMagick's montage command does not arrange images with different sizes/aspect ratios.Alphonsealphonsine
Do you think of arranging multiple images like our favourite search engine does with its picture search results? Or do you think of something more elaborated like the "trim-loss problem" ("A rule-based approach to the trim-loss problem," Int. J. Prod. Res. 20, pp. 401-415, 1991)? Anyway - interesting question...Marginate
I do not really understand what you want. If you set a common height or width for all of them, and if you also 'maybe crop' them, it is no problem at all to 'optimally arrange' them too. Or what is it that I do not understand?Microfiche
M
15

I'm not sure I understand your question correctly.

Here is what I make of it. Assuming you have 8 different images of different sizes. For demo purposes, I'll let ImageMagick create these as 8 different color patches:

convert -size  90x90  xc:yellow  y.png
convert -size 120x120 xc:red     r.png
convert -size  60x210 xc:green   g.png
convert -size 150x180 xc:blue    b.png
convert -size  30x60  xc:cyan    c.png
convert -size 150x90  xc:magenta m.png
convert -size  90x120 xc:gray    Gr.png
convert -size 120x90  xc:black   K.png

You can montage these patches in many different ways:

convert \( y.png r.png g.png  b.png +append \)  \
        \( c.png m.png Gr.png K.png +append \)  \
       -append                                  \
       -mattecolor lightblue                    \
       -frame 1x1                               \
        montage0.png

This command does not scale the different patches. It places them in 2 rows a 4 patches and montages them in their original sizes. The white spaces is where the patches do not "fit":

montage0.png

convert \( y.png r.png g.png  b.png -resize x60 +append \)  \
        \( c.png m.png Gr.png K.png -resize x60 +append \)  \
       -append                                              \
       -mattecolor lightblue                                \
       -frame 1x1                                           \
        montage1.png

This command scales all different patches to a common height of 60 pixels (preserving their respective aspect ratios) and places them in 2 rows a 4 patches:

montage1.png

convert \( y.png r.png g.png  b.png -resize 60x +append \)  \
        \( c.png m.png Gr.png K.png -resize 60x +append \)  \
       -append                                              \
       -mattecolor lightblue                                \
       -frame 1x1                                           \
        montage2.png

This command scales all different patches to a common width of 60 pixels (preserving their respective aspect ratios) and places them in 2 rows a 4 patches:

montage2.png

convert \( y.png r.png g.png  b.png -resize 60x80\! +append \)  \
        \( c.png m.png Gr.png K.png -resize 60x80\! +append \)  \
       -append                                                  \
       -mattecolor lightblue                                    \
       -frame 1x1                                               \
        montage3.png

This command scales all different patches to dimensions of 60x80 pixels (overriding their original aspect ratios) and places them in 2 rows a 4 patches:

montage3.png

Microfiche answered 17/12, 2014 at 2:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.