Noise Removal in Photos with Median Stacks (GIMP/G'MIC & Imagemagick)
In my recent experiments and playing around with even more image averaging in Imagemagick, I decided to have a look at some other methods for calculating pixel values. This time I focused on stacks of images of the same thing.
Why the same thing?
Because the (uninspired) above image was shot at ISO 25,600. Go look at it again.
To be fair, I cheated a little bit… The relatively noise-free image you see above shot at ISO 25,600 is actually combined from 10 identical shots.
The trick is that I combined all of the shots using a median evaluation in Imagemagick. This basically means that for every pixel in the image, there were 10 pixel values to choose from. Imagemagick automatically picked the pixel value that was closest to the middle.
So if we had a list of 7 values, for example, that looked like this:
Then the median value is just the number in the middle of the list:
If there were an even number of values, the median is calculated as the average of the two numbers in the middle (usually).
This is different from the averaging I had done previously, where the pixel value was an average of all the values at a given pixel location (though both methods could be used to reduce noise in the final result).
Here, let’s look at a couple of 100% crops side by side between my median stack example and a base image:
Pretty neat, right? (Seriously, look at that last image - you can’t even make out “Fast Focused Fearless” in the single shot)
There’s a few obvious caveats, though. This is only really effective for static scenes (we’ll see why shortly), and the images must be aligned very well for it to work without smearing any fine details. So it should be shot from a tripod or very stable place to minimize movement between shots, or the shots should be aligned in post (using Hugin’s align_image_stack - see here for an example of how to do it).
How to do it
There are two ways you can go to achieve this. The fast way, and the slow way.
First make sure your images are well aligned - shoot on a tripod if at all possible, and/or align the images with software as needed. Take as many as you feel like waiting on.
The fast way is with Imagemagick. Once you’ve aligned all your images (or they are spot on already), put them into a directory. Then in that directory:
convert *.jpg -evaluate-sequence median OUT.jpg
The slow way is using G’MIC in GIMP. Load up each of your aligned images as a layer in GIMP, then run G’MIC.
Then go to Layers → Blend [median] and make sure the Input Layers are All visibles, and optionally output to New layer(s).
Be prepared to wait, I’ve found the G’MIC version of this blend is 10x+ longer than doing it through Imagemagick. (Though I did poke David about this - so the G’MIC team might optimize this blend mode later).
Removing People
Using a Median filter to combine multiple images has been used to remove spurious objects from a scene. A common example is if you desire to get a shot of a famous landmark or tourist area, where there tends to be a lot of people around.
You can just shoot multiple shots (try for an odd number), and combine them with a median filter to remove the spurious objects throughout the scene.
For instance, here’s my well-used space marine traversing my desktop:
As you can see, the final frame is after combining all of the images with a median evaluation. Voila! No more space marine!
In Conclusion
This is a really neat method to use, once you realize it’s available to you, and where it can be best utilized.
If you’re shooting static scenes (stock photography, still life, etc.), there’s really no reason not to go ahead and set your camera to fire off a handful of frames quickly (burst mode!). Setup on a tripod, burst away, and you can significantly reduce the noise in your images with little effort.
If you want to capture scenes with many people/objects moving about, and want a clean image of an environment, just setup on a tripod again, and snap away. With enough frames, it’ll make combining the images and removing those objects very easy to do.
[Addendum] Just a couple of quick things that a few people have pointed out:
1. Can’t I just use a lower ISO and longer exposure? Yes - but what happens when you’ve pushed your ISO down as far as it can go on your camera? With this method, you can remove even more noise and make images that are cleaner than is possible with a single shot with your camera.
2. This is not far off from what astrophotographers will also do to clean up signal⁄noise in their images - stack multiple images to clean up the noise. In fact - there is specialized software just for this type of image stacking that I should go try out! :)