Thursday, March 3, 2011

The Magic of Median -- Goodbye, noise!

A lot of my work is stock photography. If you're doing stock work with an agency that has an approval process, you've probably had an image rejected for having too much noise (or having had too much noise reduction applied). I'd like to share a great method for getting rid of noise that won't affect sharpness or resolution one bit: Median Stacks.

Abobe introduced Median Stacks in Photoshop CS3 Extended. Almost immediately, people started using this feature to get rid of people from outdoor scenes, which it can be great for (in articles like this one). But there seems to be a great deal of misunderstanding about what median does, as in the article above where the author seems to think Photoshop is "automatically figuring out what the background is." That's not the case at all, in fact it's much simpler than that -- and the way it works can be used for MUCH more than just getting rid of unwanted people. Oh, and since that article explains how to do a median stack in Photoshop very well, I won't repeat the instructions here.

Let's start with what is actually going on in Photoshop.  If you remember your high-school math, you should know that the "median" of a set of numbers is the number exactly in the middle of the range of numbers.  For example, if you have 5 numbers:  120, 125, 128, 130, 132   the median of that group is 128.  Taking the median of a set of numbers throws out the "outliers" (in this case, the 120 and 125 on the low end,  and 130 and 132 on the high end).  If you have an even number of values in the set, the median will be calculated as the mean (simple average) between the two numbers nearest the middle.  That's all that Photoshop is doing when it calculates the median.
How does that remove people from a landscape scene?  In the article I linked to above, the photographer took six images of a scene.  In each of them there were people in one place in the image, but nothing but background in the other five.  When calculating the median, the "outlier" values of the pixels that showed people got thrown out, replaced with the median value which was just the background.  Photoshop didn't know anything about the background, nor did it have to -- it just used the median value of each pixel, and tossed the outliers.  Voila, people gone.  Nothing magic or complicated, just simple math.

Now that you know how median works, it's easy to see how a median combine of images can easily kill noise.  Noise in an image is random -- almost never the same for the same pixel of the same subject in two different images.  Sometimes the noise will add to the 'actual' pixel value, and make it higher than it should be; sometimes it will subtract from the 'actual' pixel value, making it lower than it should be.  So for one particular pixel of a scene, in 5 different images, you'll have a range of values -- some too high, some too low, some about "right."  When you median combine them, the "too high" and "too low" values (caused by noise) get tossed out, the the "about right" value gets used.  Tossing out those outlying noise-caused values, pixel by pixel over the entire scene, gets rid of the noise.  Very, very effectively.

The two images above are the same scene, shot at ISO 100, with the camera on a sturdy tripod.  The one on the top is a single image, while the one on the bottom is a median stack of 6 images.  Viewed small, it can be hard to see any difference (click on the images to see an 800x533 size).  But when viewing actual pixels, the difference is stunning.  The opening image in this post is a comparison of a single image, a median stack of 3 images, and a median stack of 6 images (I'll repeat it here):
The difference in the noise levels (front of the piano key) is obvious. Even at ISO 100, in a well-exposed image, there's visible noise. The median stack of three reduces that noise considerably, the median stack of 6 images has removed it almost entirely. That is the "magic of median." This "magic," however, is very well defined mathematically, from signal processing theory: in a median combine of images, the noise decreases as the square of the number of images in the stack. That means that if you use combine 3 images, you get 9 times less noise (3 squared is 9). Use 6 images, you get 36 times less noise. With no effect of any kind on sharpness (like noise-reduction software has). Signal to noise ratio goes up, noise is drastically reduced.
The effect is even more noticeable at higher ISO values, where there is more noise to start with. Take the two shots below, done at ISO 400:

The image on the top is, again, a single shot; the one on the bottom is a median stack of six images. Even at a small size you should be able to see the difference in the noise; in the actual pixel close-up below, it's very obvious.
Once again, the magic of median does wonders.
You do need to use a tripod, and preferably a remote release, to keep the camera from shifting between frames.  You should use manual exposure (not auto) so that the exposures are all the same, and once you've set focus for the first image, lock it down by switching your lens to manual focus and not touching it.  But for these kinds of "static" scenes where you can do those things, and nothing moves between shots, firing off 5 or 6 identical frames and putting them in a median stack will zap noise with no side effects whatsoever.

I've found that 5 or 6 images is enough to deal with noise in most scenes.  If the image I'm going to be making is going to be printed very large, though, I'll often do 10 or 12 individual images and stack them.  The resulting median-stacked image is nearly completely noiseless, even if shot at a high ISO value -- and big prints made from them have an almost surreal look from the complete lack of noise.  Try it some time.
In my next post, I'll address some issues to watch out for with median stacking, especially when doing outdoor scenes where things can (and do!) move between shots.  Just keep the median stack in mind next time you're doing a static studio scene, and want to have a gorgeous, nearly noise-free image.  Median's magic goes a lot further than simply getting rid of people.


  1. Paul, it's great to see you posting again! I especially enjoyed this latest article!

  2. Thanks, Jesse. Got so busy making a living, it was hard to post. Things are a bit more manageable now :)