Skip

How can I generate an "average image" from 200 photographs?
September 7, 2010 10:05 PM   Subscribe

How can I generate an "average image" from 200 photographs?

I have 200 photographs, and I want to generate an image that is the "average" of all of them. (Here's an example of a guy doing it with photos of houses.) How can I go about doing this? I have a Mac, Automator and Photoshop Elements if that helps. And if Photoshop is the way to go, which is the best "kind of layering" to achieve a good average? 200 layers each at 0.5% opacity? On a black, white or transparent background? Using "normal", "multiply" or something else?

Any help welcome - as the internet has little to say about how to achieve this effect, I hope your answers will be of help to people other than me as well.
posted by so_necessary to Technology (17 answers total) 9 users marked this as a favorite
 
If your images are all of the same size, you could use Imagemagick's average option to merge them into one averaged images. With some tweaking, you could use the script in the page I linked within an Automator flow, no Photoshop required.
posted by Blazecock Pileon at 10:14 PM on September 7, 2010


They are all the same size! Now just to work out how to use Imagemagick...
posted by so_necessary at 10:22 PM on September 7, 2010


The clearest way to do this is to keep averaging pairs of images:
1. Create 100 new images by averaging image 1&2, 3&4, ... up to 199&200.
2. Create 50 images from the new 100 the same way.
3. Ditto 25
4. Now it gets a little tricky. The easy way is to remove one of the 25 images--at this point they will all look pretty mushy and alike, so just drop the one you like least. Then average the remaining 24 down to 12.
5. Ditto 6
6. Ditto 3
7. Now just average 3 together: Image 2 over image 1 at 50% transparency. Image 3 over the previous at 33% transparency.
8 All done.
posted by hexatron at 10:39 PM on September 7, 2010


An array- or image-oriented programming environment such as IDL or Matlab could do this easily without the tedious manual labor Hexatron describes. GDL and Gnu Octave are partially complete, free, open source clones of those respective programs. If you don't have programming experience, try the 'Z Project' function of Stack Mode processing in ImageJ, a free graphical program. The function is documented about halfway down this page, and you'll probably need to read the overview of stack processing too.

If you are in a hurry and don't have time to learn these programs, I could do it in IDL for you. MeFi Mail me if you want to send me a zip file of the images.
posted by scose at 10:57 PM on September 7, 2010


In your linked examples tech notes he says he uses imagemagick for this
posted by stuartmm at 10:57 PM on September 7, 2010


Oh, good point stuartmm. I should probably try that then.

Right now I'm trying to work out where to type the stuff in these blue boxes...
posted by so_necessary at 11:18 PM on September 7, 2010


Right now I'm trying to work out where to type the stuff in these blue boxes...

Open the Terminal application. This is in your Utilities folder, which is inside the Applications folder.

When you open a new Terminal window or tab, you'll get a shell prompt. That prompt is where you type commands.
posted by Blazecock Pileon at 11:22 PM on September 7, 2010


I've been doing similar blending, but with aligned photographs of the same scene from slightly different angles, and have been using a python script based on the one at the bottom of this blog entry by Mike Warot.

To use it, copy the script to a plain text file (in Text Edit, select Format > Make Plain Text before saving) in the same directory as your images. Then, open a terminal window (as Blazecock Pileon described above), type "cd " (without the quotes) and then drag the folder containing your images onto the terminal window. You can then hit enter to change to that directory. Assuming your images have names like photo1.jpg, photo2.jpg, photo87.jpg..., you can then type "python 'photo*.jpg'" into the terminal window, hit enter, and merge.jpg will then be created, the image you're looking for. If you don't want to save all the in-progress images (trail1.jpg, etc), you can edit the python script to add a # at the beginning of the next-to-last line, commenting it out.

You will likely need to install the Python Imaging Library for this to work. To check, open a terminal window, type "python", hit return, then type "import Image" and hit return. If it just goes to the next line, the library is already installed. If it prints out "ImportError: No module named Image", you will need to install it first. It's been a while since I installed it, but these instructions look reasonable. The fixed with commands in those instructions get typed into a terminal window (after you change to the directory containing your download, using the same method described above).
posted by JiBB at 11:53 PM on September 7, 2010


If you decide to go with Photoshop CS3 Extended or later:

1) File > Scripts > Load Files into Stack... and click the "Attempt to Automatically Align Source Images" checkbox if you want to try and align them. This will take quite a while with 200 images - go get lunch. If you don't align them, it'll go a lot quicker.
2) Select > All Layers
3) Layer > Smart Objects > Convert To Smart Object
4) Layer > Smart Objects > Stack Mode > Mean

There's a tutorial on using this to remove tourists from a set of photos that may also interest you. The techniques are pretty similar.
posted by DaveP at 3:41 AM on September 8, 2010


If you have access to Mathematica you use use:
Image[Mean[Map[ImageData, images]]]
Here's a screen capture of that applied to some random images from Google image search.
posted by hAndrew at 5:20 AM on September 8, 2010 [1 favorite]


1. Create 100 new images by averaging image 1&2, 3&4, ... up to 199&200.
....
7. Now just average 3 together: Image 2 over image 1 at 50% transparency. Image 3 over the previous at 33% transparency.
8 All done.
posted by hexatron


Another way to do it just using the blend X %transparency operator, is to blend each picture in with a running proportion like this:

blend 50% of 2 into 1, creating TEMP
blend 33% of 3 into TEMP, resave
blend 25% of 4 into TEMP, resave
blend 20% of 5 into TEMP, resave
... on like this until
blend 1% of 100 into TEMP, save the final result.

Pretty easy if you can script it.
posted by StickyCarpet at 8:49 AM on September 8, 2010


Just to be clear, with 100 pictures, each gets blended into the TEMP result at 1/frame-number percent.
posted by StickyCarpet at 8:54 AM on September 8, 2010


times a hundred
posted by StickyCarpet at 8:55 AM on September 8, 2010


Now if so_necessary is doing this to medical diagnostic images, they'll want to make sure they are using 16 bits per component in the TEMP image, and they shouldn't skip any images.
posted by StickyCarpet at 9:02 AM on September 8, 2010


Sorry, Sticky, the shrinking percentages blend is a fail unless the TEMP image has resolution to burn. For example:

Suppose you are working with 8-bit images. The 100th image, at 1% blend, will only has the values 0 (for pvalues 0-99) 1 (for pvalues 100-199) and 2 (200-255). So almost all information in the image will be lost. If there are more than 255 images, well, any images past 255 get mapped to 0 before the interpolation, so they have no effect at all.

Welcome to the World of Roundoff Error Terror.
posted by hexatron at 8:58 AM on September 9, 2010


100 8-bit images sounds like more, rather than less. But I bow down to hexatron on all things computational, except maybe that "pick one frame to delete", wtf?
posted by StickyCarpet at 12:44 AM on September 10, 2010


except maybe that "pick one frame to delete", wtf?

25 has no small prime factors (where small is <= 3), while 24 does. Alternately, 100 has non-small prime factors, while 96 = 2^5 * 3. So, assuming you really don't feel like merging 5 images at once, 96 is much easier.
posted by JiBB at 1:20 AM on September 10, 2010 [1 favorite]


« Older How do I find a job in LA befo...   |  Calling all math lovers! Great... Newer »
This thread is closed to new comments.


Post