ImageMagick Average Blending Files

Back in 2003 Xeni Jardin posting on boingboing highlighted artist Jason Salavon's work involving averaging together Playboy centerfolds by decade. The works he produced were haunting and beautiful to me (and a little geeky, too).


Those four images represented the four decades from the 1960's to the 1990's (left to right). The prints were made with code that he wrote in C on Unix based SGI machines.

These "Amalgamations" (to coin his phrase), are simply stunning to me. So in the sincerest form of flattery, I had to see if I could replicate the results in some fashion with more modern tools (Jason began his work blending the Playboy images back in 1997).

My first thought was to approach this using GIMP. After a few tries and experimenting I found that a better approach would be to use ImageMagick instead. It's just better suited for this type of processing.

Let's have a look at the results before we delve into the ImageMagick commands...

My first attempt was to replicate the results against all of the 1960's centerfolds to see if I could attain something similar (to validate the process):


Results after averaging all the centerfolds.

After running Levels → Auto in GIMP.


Overall I was pretty happy with the results!

In my case I rotated any images that were wider than they were tall to maintain the aspect ratio. While I was testing out the commands I also thought it would be neat to allow the horizontal images to remain that way, and to pad the dimensions to create a square result:


Not rotating the horizontal images, and centering/squaring produces this.

The result here is interesting because we also get a feel for the frequency of using horizontal spreads vs. vertical.

So I can confirm that the method appears to work. Just how do we do this?


ImageMagick Commands


There are two major things to consider when approaching this process:
  1. Are the image sizes the same? If not we will have to resize and expand
  2. Do you want to rotate horizontal images, or leave them as is?

These two options will have an influence on how we approach the commands we use. I will assume (to be safe) that none of my images are quite the same size, and that I do want to rotate wider images.

I also scanned through my images and determined that a the smallest image I wanted (or had available) would be 792x1728 - I will want to shrink all images that are larger than this to fit.

Here is the full command I used:

convert -background transparent *.jpg -rotate "90>" -resize "792x1728>" -gravity center -extent 792x1728 -evaluate-sequence mean output-rotated.jpg

ImageMagick commands are lately best read portion by portion as they operate on your images, so let's break this down:

convert -background transparent *.jpg
Start the "convert" command up, and set the background color to transparent for my operations. Also, load up all of my jpg files into memory.


-rotate "90>"
If any of the images are wider than they are high, rotate them 90°.


-resize "792x1728>"
Any images larger than 792x1728 should be resized down to fit in these dimensions (maintaining aspect ratio).


-gravity center -extent 792x1728
Keeping the images centered, extend the images so that they fill up the 792x1728 space (the padding will be filled with the background color - transparent).


-evaluate-sequence mean output-rotated.jpg
Finally, once all the images are now rotated and the same size, do an arithmetic mean on their pixels (average), and write the final output to output-rotated.jpg


Another version of the command above can be modified if I do not want to rotate any horizontal images (to create the square version above):
convert -background transparent *.jpg \
-gravity center -extent 1728x1728 \
-evaluate-sequence mean \
output-non-rotated.jpg
In this case I am not rotating anything, and padding all my images with transparency up to the extent size (1728x1728), then running the average. It should be noted that 1728x1728 is as large or larger than all of my images (otherwise a resize would be required).

More Results


With the command line stuff out of the way, let's take a look at some more interesting results I obtained playing with these options!

Continuing with the theme of Playboy centerfolds, here are the 1970's:


1970's normalized.

And what would decades of Playboy covers look like? (Honestly, the hardest part of creating these at this point is finding a decent archive of Playboy covers to use as source material... I would almost consider springing for the Playboy Cover to Cover Hard Drive - Every Issue From 1953 to 2010 if it wasn't so damn expensive!)


1950's

1960's




1970's

1980's




1990's


It would appear that over the years Playboy finally dialed in their title placement, as well as their model placements on the cover (they really got there in the 80's best, I think).

Enough with the Playboy, I think. At this point my keywords are going to make my blog look like a spam site. So let's switch over to something slightly less salacious, and have a look at all the covers of the Sports Illustrated Swimsuit issue! :)


Every cover of the SI Swimsuit edition through early 2000.

And let's finish up with something just a little more classy. Alberto Vargas may be the most famous name in classic Pin-up paintings, and interestingly the combination of all of his paintings is a little more tame. I came across a nice archive of his work at The Pin-up Files website.


All of Alberto Vargas' paintings at once.

Gil Elvgren is another famous name in Pin-up artwork. Here's a taste of what he produces when combined:


Gil Elvgren's works combined

And for something just a little more contemporary, here is a blend of all the headshots from Peter Hurley's sample portfolio of Leading Ladies:


Peter Hurley's Leading Ladies

In each of these I brought the final output images into GIMP for adjusting levels. I normally just went ahead and let the Levels tool auto-adjust for me, but I did look at stretching contrast (+hsv) to see the results. In the end I think I preferred the Levels → Auto the best.

Give it a try and let me know how it turns out, I'd love to see some other cool visualizations of sets of photos in this way!

Also, if Jason Salavon ever reads this - thank you for turning me on to a great and interesting processing technique! Your results are amazing!

I've also tried my hand at blending a bunch of celebrity faces together as well, have a look here:
More Averaging Photos (Martin Schoeller)

13 comments:

  1. I have seen images like these in various places, but never attempted them. Somehow, you put it together in a way that made me want to give it a shot. Thank you.

    ReplyDelete
    Replies
    1. Fantastic! I'm glad to pay it forward and see if anyone else might enjoy these the way I did. They are addictive once you get started.

      Delete
  2. Replies
    1. Thanks! I have something funnier coming shortly after playing with this for a bit...

      Delete
  3. ...where in the world did you get the source images from??? :-)
    Great work!

    ReplyDelete
    Replies
    1. I know, it was a seriously large PITA to find all the source images I needed in a decent resolution! I had to scour some strange corners of the internet to find the playboy covers and centerfolds...

      Delete
  4. Funny! I tried something similar a few months ago, but doing it with Playboy covers is hilarious :-)

    I didn't realize this was possible with ImageMagick, so I wrote some (dirty) code for that.

    This one with my phone contact photos: http://www.flickr.com/photos/rsamaniego/6771555543
    This one with a publicly available image database: http://www.flickr.com/photos/rsamaniego/6771759021

    Source code: http://www.xente.mundo-r.com/fujur/imagesmean.tar.gz

    Regards and happy averaging! ;-)

    ReplyDelete
    Replies
    1. Oh man, nice job on using the Massachusetts University database - and the results are wild!

      Delete
  5. Great blog writing covering this technique. Thanks Patrick! This will work really well for series of images that are similar in layout or poses. Very interesting.

    ReplyDelete
    Replies
    1. Thanks Jimmy! There's all sorts of neat results that I've been seeing. For instance, I was playing with movie posters too...

      The real trick is to align on a feature in all the images that's important. For instance, I re-did the Martin Schoeller portraits, but was even more careful to make sure the alignment on the eyes was spot on - the results are much better I think.

      Delete
  6. I can't thank you enough for this educational look at image stacking. Wow! I couldn't get the Gimp to do what I wanted it to. But Image Magic? Great straight out of the commandline. Wonderful tools, these.

    ReplyDelete
  7. Thanks so much for this tutorial. It's going to be really helpful for removing noise in an animation project I'm working on. Another artist who's worked with averaging images is Jim Campbell:
    http://www.jimcampbell.tv/portfolio/still_image_works/illuminated_averages/index.html
    He came to my college (RPI) around 2005 and I remember him saying he created those images with hardware he built himself, not software.

    ReplyDelete
    Replies
    1. You're very welcome! I'm glad it'll be helpful. And thatnks for that link, his work is really fantastic (hardware? Wonder if it's looong exposures?)

      Delete