Linux.com

- Enter Here to Research Featured Solutions -
  • Sponsor - HP

    • Open source and Linux from HP


      Featuring nine consecutive years of Linux market leadership to countless sponsorships, contributions, and forward-thinking initiatives to support the advance of open source and its community. HP is the advisor you can trust today for proven solutions you can value for the long run.

      See how committed we are to open source and Linux, including our recent FOSS governance and tools analysis initiative involving FOSSology and FOSSBazaar.

      » Get your FOSS in gear right here.

Feature: Tools & Utilities

Unshaking and refocusing your photos

By Nathan Willis on January 21, 2008 (9:00:00 PM)


Printer friendly page Print
Comment on this article Comments

Whether by wind, vibration, or shaky hand, we have all taken blurry photos. But in the digital era, there is no need to despair -- you can remove shake and blur from your pictures after the fact. Several Linux-friendly utilities can help you.

Deconvolution is the general process that helps remove the effects of camera shake and blur. If you want to understand the math behind the process, start with the articles referenced at Wikipedia and you can find as much detail as you want. In a nutshell, it involves taking the Fast Fourier Transform of the image (which makes it easier to see the tell-tale signs of blurring), smoothing out the artifacts, then transforming the image back into its original form. It is a CPU-intensive process, but for a shaky image there is no better use of your MHz.

Unshake

Unshake

The most straightforward way to get started is with Mark Cahill's Unshake, a small Java app with a lot of options that performs some helpful guesswork to speed things up. The latest release is 1.5, which requires Java 2 or greater. Unshake is closed source, and the license prevents use for commercial purposes.

You can unpack the distribution anywhere on your system and launch the app by running ./unlaunch.sh. The interface has controls at the top, a status window beneath them, and a clickable file selection widget at the very bottom. When you open a photo, you start by resizing the photo window to show just the portion of the image that you are most concerned about. This is a critical step, and one that the interface does not explain to you. If you choose the wrong portion of the image, Unshake could misidentify portions of it as blur and overdo the correction.

Unshake results

When the window is properly set, click on the Estimate button and Unshake will give its best guess as to how long the process will take. You can adjust the blur severity and correction quality parameters and get new estimates. To see the results, just click the DeBlur button. Unshake will perform the image correction and open the result in a new window, which you can then save.

Unshake attempts to determine on its own how much correction to apply. The actual processing time can vary greatly depending on what it decides. The Time control allows you to allot more or less time to Unshake's process. By default it is set to "x1" meaning that Unshake will perform its transformations within the Estimate time. You can turn the Time parameter all the way to "x100" if you want the algorithm to perform more detailed analysis.

At the default settings, 40 to 50 seconds is a reasonable estimate time for a 1.3 megapixel image. Cahill notes on the Unshake site that he has never seen the algorithm come close to the "x100" time allotment -- he just put it in as an upper bound to make sure the program exits.

Refocus

The GIMP has two third-party plugins that do the same kind of correction as Unshake. Both are open source, although neither of them seems to be undergoing active development.

The first is Refocus, which is officially at version 0.9.0. That release is from 2003, though, and several other developers have released their own patches to bring Refocus compatibility up to modern versions of the GIMP. Richard Lemieux and Peter Heckert each maintain a page for their respective patched versions. Debian and Ubuntu include Lemieux's version as 0.9.1 in their package managers.

You start Refocus from within the GIMP, in Filters -> Enhance menu. The tool has five parameters and a preview window. It is not easy to explain the parameters without delving into deconvolution math, but you can play around with the settings. Roughly speaking, the Radius and Matrix Size controls determine how small a blur the algorithm will detect, and the Gauss, Correlation, and Noise controls affect the degree of smoothness and pixelization artifacts to allow.

In my tests, Refocus was drastically faster than Unshake, taking less than five seconds than to deblur an image that required 30 or 40 in the latter program. Of course, one of Unshake's selling points is that it performs its own automatic tweaking, thus producing higher-quality output.

Iterative Refocus

The other helpful GIMP plugin is named Iterative Refocus (or refocus-it). Its last release was 2.0.0, in 2004, but unlike Refocus no one that I am aware of is putting effort into making sure it remains compatible with newer versions of the GIMP.

Fedora provides the plugin as the gimp-refocus-it package, but users of other distros will probably need to compile from source. Fortunately, this is simple. Make sure that you have the GIMP development libraries installed, then execute the old ./configure; make; make install three-step. On Ubuntu 7.10, I found that I needed to create the directories /usr/local/share/help/C and /usr/local/share/help/images. You could also attempt to alter the Makefile to correct for this problem, but creating the directories is faster.

Once installed, Iterative Refocus also shows up in the Filters -> Enhance menu. Iterative Refocus has more options than Refocus, including the ability to specify the direction and size of the motion blur in the image. Knowing this allows you to better correct for the blur's ill effects -- but of course it is rarely simple. The worst kind of motion blur is not in a straight line, it is multi-directional or circular. Still, if you can zoom in on the image and determine which direction and how far it stretches, you are that much closer to eliminating it.

As its name implies, this plugin makes multiple iterations, correcting a little bit more on each pass. As with the other settings, it is often subjective how many iterations improve the image, but you can get a good feel for the quality of the output using the Preview button on a few.

No silver bullet

If you watch the movies, you have probably seen the impossibly accurate "computer enhancement" hand-waving that turns a blurry mess into a crystal clear mug shot or license plate for the hero to chase. Real-world image enhancement is not that good, but you may still be surprised at the level of quality a good Fast Fourier Transform and deconvolution can produce.

All three of these applications produce admirable results. Refocus is the fastest, and subjectively Unshake produces the cleanest results. It is unfortunate that among the three alternatives, one is not free software and the other two lack active maintainership. But since the math is well understood, maybe someone will pick up where the other programmers left off, and bring even better refocusing technology to the image editors of tomorrow.

Slashdot Slashdot it!   -   del.icio.us del.icio.us   -   Digg This!

Comments

on Unshaking and refocusing your photos

Note: Comments are owned by the poster. We are not responsible for their content.

Closed source = nonsense

Posted by: Anonymous on January 22, 2008 10:35 AM
If it's not GPL, don't even bother telling us about it.

#

Re: Closed source = nonsense

Posted by: Anonymous on January 22, 2008 08:06 PM
Very clever. A mind like a steel trap - rusted shut. Some of us still live and work in the real world. Sometimes closed source is still the best option, please do bother telling us about ALL available options.

#

simg

Posted by: Anonymous on January 22, 2008 11:19 AM
Another program which can do deconvolution on images is a gpl program designed for processing astronomical images called simg. http://www.simg.de/index.e.html

#

Unshaking and refocusing your photos

Posted by: Anonymous on January 22, 2008 04:14 PM
It´s kinda bonkers that you mates are publishing closed source stuff in this page. Closed source is the devil, mate!

#

Re: Unshaking and refocusing your photos

Posted by: Nathan Willis on January 22, 2008 11:40 PM
Well now, if seeing the closed source app get higher marks than the open source abandonware bothers you ... perhaps the last sentence of the story will motivate you? Or someone you know? -- Nate

#

http://www.radikal.in

Posted by: Anonymous on January 22, 2008 04:33 PM
Perfect one article , Thank You..

#

Unshaking and refocusing your photos

Posted by: Anonymous on January 22, 2008 04:33 PM
http://www.radikal.in

#

Unshaking and refocusing your photos

Posted by: Anonymous on January 25, 2008 11:59 AM
There are other closed source applications for photography and scanning that are not that expensive, and are wonderful to use, and are written for LINUX. There is a value! As the projects that don't get maintained are not worth that much, paying someone a little (not a company but a person) for the value of a maintained product, is like giving them a donation. I look at a software product that is proprietary and think of it as a donation, the same as when I buy music cd at a concert of blue grass artists that I *know* need the money and that the record company is not making money from. Microsoft, the price that they charge, just to charge you over and over and over again, for the same thing, well - I just don't like to pay them anything. However, these folks that have labored by themselves for years to get a software to do what they want it to do... for a purpose (usually to satisfy their own need for a software that does something), well, Hey I will pay them a few bucks (no problems mate).

#

Licensing is lame, nice to know about unusable "superior" programs

Posted by: Anonymous on January 30, 2008 07:39 AM
It's not just that it's closed source, which is bad enough. But the restriction on how one uses the program (i.e; commercial use) put it out of the running for anyone who has "real work" to do. You wouldn't break the law and dishonor the developer's license, would you?

#

Unshaking and refocusing your photos

Posted by: Anonymous on February 01, 2008 09:25 AM
bla bla bla

#


Post a new comment

Name : Anonymous


Copy the word from the image on the left into the input box.
Linux UNIX Password Mgmt
Create/Change/Secure/UIDs/PWDs Free 30 Day Trial w/ Tech Support

 
click here