4

I would like to create a TreeMap, using pictures to fill out the treemap rectangles. I can assume that all the pictures have the same width and height (i.e. the aspect ratio). Thus, I need a treemapping algorithm to create the rectangles with a given ratio, do I will be able to put the pictures there (and perhaps scale the pictures if I need).

Could you recommend one ?

Martin DeMello
  • 11,876
  • 7
  • 49
  • 64
Michael
  • 41,026
  • 70
  • 193
  • 341
  • Should the pictures have different scale in the treemap, in that case what determines the relative size of each image? – Albin Sunnanbo Feb 26 '11 at 20:44
  • 1
    Edge case: Assume you have three images with the same aspect ratio as the TreeMap you want to draw (to make it easier to think about it, you can first assume they are all square). How would you scale and fit those three images in the treemap? You may draw an ugly drawing in paintbrush and include in your question. – Albin Sunnanbo Feb 26 '11 at 20:48

1 Answers1

8

In general, a solution is not possible - Albin Sunnanbo has provided a proof by counterexample. Assuming your bounding rectangle has the same aspect ratio as your target rectangles, you might be able to get a good-enough solution by scaling the bounding rectangle to be a square, running the squarified treemap[pdf] algorithm over it, and then scaling back to a rectangle. Since the squarified treemap doesn't guarantee perfect squares, your final rectangles will not have a perfect aspect ratio, but in practice it might not distort your pictures too much.

A nice refinement would be to run a seam carving pass over your pictures to fit them properly into the slightly-off aspect-ratio rectangles; if you're using this to assemble a collage, for instance, you should get visually pleasing results out of this.

Martin DeMello
  • 11,876
  • 7
  • 49
  • 64