How to Use Median Averaging to Get Better Photos
Median averaging can fix your photos by making pesky tourists disappear, leaving you with a clear view of your subject.
Well, have you ever tried to take a picture of a fantastic landmark, only to have your efforts to get the perfect clean shot thwarted by wandering tourists? If so, and if in the future you’d like to get rid of those aberrations, median averaging can help. Here’s how: First, you’ll need to take several pictures of your scene (five or more pictures capturing the same area is ideal). Each successive shot should be taken several seconds apart—at least long enough that the people wandering around have rearranged themselves. The idea is that in one (or at most a few) of the images a tourist might be blocking some portion of the background you’re interested in, but the background will be exposed in the majority of the pictures (this means the scene can’t be too crowded—the technique is awesome, but it’s not magical).
Here’s where the pixel-nature of digital images comes into play. Let’s imagine that in each of the images you take of your landmark, the same pixel (say the top-left one) is capturing light from the same bit of background (perhaps a dark portion of a statue). That pixel will have a low value in almost all the images since there isn’t much light coming from it—except, perhaps, in that one picture where a tourist with a bright white T-shirt is standing in the way. In that image, the pixel will have a high value as a result of the brightness of the T-shirt. If that T-shirt laden image were the only shot you had of the statue, your final picture would obviously feature the shirt. However, that’s not your only picture—you have many T-shirt-free images too. So why not use them to replace the T-shirt tainted pixel? And if you use this idea to replace every aberrant pixel in the image, you will get an image with no T-shirts or tourists whatsoever.
But what’s the best way to do this? Well, if you create a new image in which the value of each pixel (low for dark regions, and high for bright) is obtained by finding the median value of that same pixel in all the images, you’ll get exactly the result you’re after. In other words, the median value will throw out the outlying pixel values (belonging to T-shirts and the people wearing them), and will leave you with a clear view of the landmark! Why the median and not the mean? Well, in our case, the pixel of interest had a low value (meaning dark) in each of the pictures except the one with the bright T-shirt. The mean value of this pixel across all the images would be thrown off by this single high value, and the resulting pixel would be way too bright. Just as with the bag of crushed potato chips, the median value gives us a way to get rid of the effects of aberrant data and obtain a true representation of the typical value.
But how exactly do you go about finding this median value for each pixel in your set of digital images? It’s an impressive trick to see, so be sure to check out the Math Dude “Video Extra!” episode on YouTube for a demo. And you can try it out yourself with your own pictures using the free Tourist Remover. Have fun!