Beginning to Think about Sharpness
Posted by Tom Benedict on 10/05/2010
The weather prediction did work well, and the charts from the National Weather Service were right on the money when it came to figuring out where there would be cloud cover, rain, etc. I wound up intentionally picking a spot with “bad” weather, but not so bad that it would result in precipitation. There’s an old adage that bad weather is good for photography. It’s true. Bland skies are boring. Skies boiling with clouds are interesting. I opted for interesting.
It worked, and the photo session resulted in a number of good image sets for panoramas. Few errors, good image spacing, and almost nine hundred images to choose from. Excited, I blindly began stitching before really taking a close look at the images themselves. The stitching went great, but a number of the images were unacceptably blurry.
This brought back an old goal I’d set for myself ages ago: To have a program I could run on a set of images taken in a given location, and be told, in a quantifiable way, which were the sharpest of the bunch.
Doing a Google search on “image sharpness” or “how sharp is my image?” brings up all manner of pages describing the follies of attempting to apply numerical methods such as the mean transfer function to an image in order to judge the sharpness of the lens involved. It brings up other cautionary articles that urge people not to attempt to quantify sharpness in any sort of repeatable scientific manner since it depends so much on the source image being used.
I’m not trying to measure the quality of my lens. I’m trying to find out which shots I screwed up, and cull them without having to wade through a zillion shots!
I poked around a little, and found something that appears to work. With a lot of my image processing work, I tend to turn to ImageMagick, a set of command-line tools for image manipulation that will run under most operating systems. I use them under Linux at home, and on either Linux or Cygwin at work. They’re flexible, powerful, often dog slow, but they almost invariably get the job done.
In this case I wound up using two tools: convert and compare. To measure sharpness, I decided to make a blurry copy of an image, and find out how much damage was done. If there’s no big change, the image was likely blurry to begin with. If there’s a huge difference, chances are the image was pretty sharp, and the blurring action did a lot of damage. So here’s how I did it:
convert -blur 2 source.jpg source-blur.jpg
compare -verbose -metric RMSE source.jpg source-blur.jpg source-diff.jpg
This spits out a number representing the root mean square error between the source and blurred images. It also results in an image file showing that difference. For my purposes I didn’t want to keep the blurry or difference images, so I deleted them after they were generated.
I ran some tests on the set of images I did over the weekend, and it appeared to work quite well. I can’t say what number represents “sharp” or “blurry” because what those articles said is true: it depends too much on what the source image is. But for a given set of images I can run this test, associate a number with each image file, look through a range of images, and determine what I’m willing to work with. At that point it’s a simple matter of rejecting whichever images have an RMSE number lower than my threshold, and retaining the images with an RMSE number higher than my threshold.
The only down-side to this is that it’s time-intensive to run: upwards of 20 seconds per image. It doesn’t seem like much, but once you get up to 800, 900, or 1000 images from a single shoot (typical for a panorama-intensive session) this starts to drag. Nonetheless, with ImageMagick it’s possible to script the whole mess, set it running, and walk away until it’s done. Sometimes computers really can make life easier.
So far tests is as far as I’ve gone with this. But once it finishes running the software on the set from this weekend, I’ll be in a position to try using the information to build sharper panoramas with less work.