Page 1 of 1

[SOLVED] Combining images: How to optimize image placement?

Posted: 2016-08-03T09:01:34-07:00
by 4aiman
Hello Everyone!
Many thanks for the ImageMagick!


I'd like to know whether it is possible to combine multiple images of different sizes while optimizing the placement?

Say, there are some colored rectangles which represent images of different size
Now, I want to combine those into one image.

Here is what montage does:
Image

Considering white is a background, is it possible to optimize placement of the colored rectangles?
I.e. one can clearly see that there's enough space to move up both cyan and magenta rectangles.
Then the gray one might go all the way to the right and the black one either to the right or up.

The tricky part is that there might be several large rectangles which will combine with huge "spaces" in-between.
Is there any chance that ImageMagick will search such "holes" and "place" the rectangle currently being added to the image into one of those "holes" if there's enough "room" (i.e. some "hole" is bigger than the current rectangle)?

Re: Cmbining images: How to optimize image placement?

Posted: 2016-08-03T09:06:26-07:00
by fmw42
One thought is to order your images by size, largest first. Place the first image at the top left. Then search for the largest empty space and place the next largest image. Etc.

Re: Cmbining images: How to optimize image placement?

Posted: 2016-08-03T09:51:39-07:00
by snibgo
A useful "Survey on two-dimensional packing": http://cgi.csc.liv.ac.uk/~epa/surveyhtml.html

Re: Combining images: How to optimize image placement?

Posted: 2016-08-03T22:56:30-07:00
by 4aiman
Thanks. snibgo!
The survey you've linked to is very useful :)
Marking this as "solved".

Re: [SOLVED] Combining images: How to optimize image placement?

Posted: 2016-08-03T23:26:19-07:00
by fmw42
Did you implement one of those methods? If so, your code could be useful to others.