Learn how median averaging can fix your photos by making pesky tourists disappear and leaving you with a clear view of your subject.
In the last two articles we’ve learned how to calculate two types of average values: the mean and the median. Today, we’re going to continue where we left off and talk about how median averaging can be useful in everyday, real life situations. Specifically, how you can use median averaging to get better photos by making pesky tourists disappear—leaving you with a clear view of your subject.
Recap: What is the Difference Between Mean and Median?
Before we get too deep into how median averaging can fix your photos, let’s take a minute to review the difference between mean and median averaging. In the last two articles, we’ve discussed in detail how to calculate these two values using bags of potato chips as an example—so take a look at those articles if you need a refresher on how to crunch the numbers. (For more on mean values, see How to Calculate Mean Values; for more on median values, see How to Calculate Median Values.) For today, let’s concentrate on reviewing what these two quantities really mean (sorry, the pun is nearly impossible to avoid). Up first, the mean.
Recap: What is the Mean?
Imagine you have five identical glasses in front of you, each of which is filled to a different height with water. What’s the mean height of the water in these glasses? We could figure this out by measuring the heights, adding them all together, and finally dividing the result by five to get the answer. Alternatively, we could simply pour water from one glass to another until they all had the same height of water. Some glasses would lose water, others would gain. But when you measure the final height of water in the glasses, it will be the exact same value as you calculated by summing the individual quantities and dividing by five. That is exactly what the mean value means. This shifting of the water between glasses is an excellent intuitive picture for you to keep in your head to help you understand what it really means to find mean values.
Recap: What is the Median?
How about the median? Go back to imagining you’re looking at the original glasses filled with different heights of water. Now, move the glasses into a line ordered from the least amount of water to the most. The median height is the height of the water in the middle glass. In the last episode on how to calculate median values we talked about how the real power of the median lies in its ability to resist outlying values—that is, those values that are extremely aberrant (frequently these outliers are the result of something like a measurement error). In the case of our water glasses, if one glass had a lot more water than the others, the mean height would increase significantly (since we’d have to pour water from the super-full glass into the others), but the median height wouldn’t change at all.
What are Pixels in Digital Images?
So that’s the meaning of the mean and the median. Now: What can we do with them? In particular, today we’re interested in how average statistics can help us make our photos look better. But in order to talk about that, we first need to understand a few things about digital pictures and how digital cameras work. Digital cameras, including cameras on cell phones, take pictures by breaking an image into many millions of tiny discreet boxes in a grid pattern (it’s like looking through the mesh of a window screen). Each of these tiny boxes is called a pixel (short for picture element), and each of these pixels collect light. When you put them all together, these millions of pixels determine exactly how bright and precisely what color each portion of your image will be. But what does all this stuff have to do with median averaging?
How to Use Median Averaging to Get Better Photos
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 this week’s Math Dude “Video Extra!” for a demo. And you can try it out yourself with your own pictures using the free Tourist Remover tool at http://www.snapmania.com. Have fun!
Next week, we'll cover another form of average value: the mode.
Please email your math questions and comments to firstname.lastname@example.org. You can get updates about the Math Dude podcast, the “Video Extra!” episodes on YouTube, and all my other musings about math, science, and life in general by following me on Twitter. And don’t forget to join our great community of social networking math fans by becoming a fan of the Math Dude on Facebook.
Until next time, this is Jason Marshall with The Math Dude’s Quick and Dirty Tips to Make Math Easier. Thanks for reading, math fans!