Slashdot Mirror


Correcting Lens Aberrations in Digital Photography?

Kavau asks: "I've recently entered the world of digital photography, and bought a pocket-sized digital. While the resolution and the color accuracy are very nice, I was utterly disappointed by the (lack of) quality of the zoom lens: It has a clearly visible barrel distortion, especially in wide angle, so that straight lines appear curved in the picture. This is especially annoying in architectural shots or cityscapes. While grumbling about this shortcoming, I suddenly realized that I am dealing with digital imaging here: In principle it should be no problem to measure the distortion, and then to correct it with a digital mapping. Other lens faults such as vignetting could also be corrected. Now, since I don't want to reinvent the wheel, here is my question to Slashdot: Do you know of any open-source tools that deal with issues such as (1) applying general analytic transformations to a picture, (2) specifically correcting for barrel distortion, or (3) determining the amount of distortion from test pictures? Also, since people probably had this idea before, does anyone have experience with this issue that he/she wants to share, or some resources to point out?"

15 of 67 comments (clear)

  1. Seems to me... by Lendrick · · Score: 4, Informative

    ...that your best bet would be to take a picture of a piece of graph paper, and then figure out exactly how to stretch it so that the lines are straight again. That said, I'm not entirely certain if there are any programs out there that would do this, but I think it'd be reasonably easy to write an OpenGL program that allows you to apply arbitrary distortions to an image, and then saves those distortions to apply to other images.

    1. Re:Seems to me... by Mprx · · Score: 3, Informative

      I don't think the OpenGL API allows easy arbitrary distortions. Maybe have a look at the source for the various distortion plugins for the GIMP.

    2. Re:Seems to me... by Lendrick · · Score: 2, Informative

      I don't think the OpenGL API allows easy arbitrary distortions.

      Sure it does.

      The way to do it is use the original as a texture, and then draw a grid of square polygons, each with a corresponding of that texture. Allow the user to distort those squares (while leaving the texture the same) and you can distort the image. To really make this look good, you'll need to use fairly fine-grained squares, but you're not concerned with frame-rate here.

  2. PanoTools by ugglan · · Score: 5, Informative

    Check out PanoTools at http://www.path.unimelb.edu.au/~dersch/

    It has a steep learning curve, but seems to be worth the effort. I've only played around with it some myself but I've seen lots of (seemingly) professional photographers on the web that use it.

    Exellent tutorials: Big Ben's Panorama Tutorials

  3. google says... by tchuladdiass · · Score: 4, Informative

    Search string: photo barrel distortion
    4'th link down:
    www.philohome.com/barrelpers/barrelpers.htm

    It mentions to use the "panorama tools" package, which is open source. However, from what I remember, someone sued the author for patent infringement or something, so he no longer has it on his web site www.fh-furtwangen.de/~dersch/, but I found it on www.path.unimelb.edu.au/~dersch/

  4. Photoshop options by cgenman · · Score: 2, Informative

    I know, I know, not freeware. Yet everyone seems to have a copy.

    a creative pro article about correcting barrel distortion, and one at Fred Miranda.

  5. DLT by MountainLogic · · Score: 5, Informative
    The method for fully correcting for lens aberations is the Direct Linear Transform. It involves placing targets at known locations in the object field, recording their location in the film plane, then solve for this real ugly transform matix. You can then take a pixel in film space, run it through the solved matrix and get that pixels location in meat space (well really just that pixel's vector for a 2d camera system). You can also do this with two fixed cameras to solve for 3d location. I've had no trouble resolving targets down to 1/4 pixel accuracy. The only referance I have off of the top of my head is:

    Woodle, Alan S., Scott Elliott: The Vector system for dynamic gait analysis. Clinics in podiatric medicine and surgery. 10(3)485-500, 1993.

    There are referances to the math in that paper. Good key words to google might be DLT & photogrametry (sp?)

  6. VIPS & NIP by Yarn · · Score: 4, Informative

    VIPS is a wonderful image processing library with all sorts of "evil stuff", NIP is a GTK interface to the library which gives you a kind of spreadsheet for images. I'm telling the author about this slashdot item so he can come and pimp it here himself, but in the mean time take a look.

    I have personally used it for analysis of medical images, it's nice and versatile, although the built in scripting language is a bit sick (imo).

    --
    -Yarn - Rio Karma: Excellent
    1. Re:VIPS & NIP by jcupitt65 · · Score: 2, Informative

      Hi, I'm the VIPS maintainer. Thanks for the plug Yarn :)

      It has a rubbersheet tool. You make a target image (a black and white chessboard works well), print the target out, take a picture of it (you'll need to pick a particular zoom setting to calibrate), and feed the original (undistored) image and the (distorted) photo into the transformation estimator.

      The estimator uses gradient analysis to iteratively discover a 0/1/2nd order transform from the distorted image back to the original. It won't work so well at the image edges (you'll need to crop the corrected image down a bit), but mostly it works pretty well. I use it on 10,000 by 10,000 pixel images without problems. For pincushion/barell distortions it should get you a fixed image to less than a pixel error.

      Downside: VIPS is GPL and the transform stuff was done by a friend of mine as part of his PhD. He doesn't want to GPL it, so the transform stuff is distributed as a binary plugin. The windows and suse binaries on the website include it.

  7. photoshop plugin by foniksonik · · Score: 4, Informative


    http://www.humansoftware.com/pages1200/PhotoFixlen s/HSphotofixlens11.html

    Photoshop plugin for exactly this issue. Dont' know how well it works but it may be just waht you're looking for... Mac and Windows.

    --
    A fool throws a stone into a well and a thousand sages can not remove it.
  8. Try Intel's Open Source Computer Vision Library by hamjudo · · Score: 3, Informative
    Intel's Open CV.

    It worked for me a couple years ago with cheap USB cameras. I haven't used it recently, so I want to know if there are better choices now. I've got a new robot platform with a lot more CPU power and USB bandwidth, so I'm going to try working on the vision thing again.

    Back then, I started with the instructions at Program Your Computer to See. Note how the URLs inside the article are mostly out of date.

  9. Re:Nothing new here by hamjudo · · Score: 2, Informative
    The warping depends on distance from the lens.

    That's not quite right, so leave your shorts where they belong.

    The warping changes as you change focus or zoom. How much it changes depends on the quality of the lens.

    If you zoom in, you may need to recalibrate your dewarping transform.

    Cheap cameras that don't autofocus or zoom have an advantage here.

  10. Objective reality of 3-d space by Hell+O'World · · Score: 4, Informative
    Those curved lines you are experiencing are not an artifact of your lens. They are the inevitable result of living in a 3-D world. They occur because you are mapping straight 3-D lines onto a curved picture plane.


    You may be familiar with the concept of a picture plane that is used in perspective drawings. The idea is that a transparent sheet is placed between the object and the eye, and rays are mapped onto the surface. That works fine for narrow fields of vision, but it falls apart as the lens gets wider.

    Imagine an extreme case: You are standing in a train station. To your left the tracks disappear to a point on the horizon, straight ahead of you the train sits, and to your right the tracks disappear off to another point. If this image is cut up into small enought chunks, you won't notice the abberations of traditional perspective. You have a one point perspective of the train, and a two point perspective on each side. But try to stitch the images into a whole, which is similar to what you are trying to do with a wide angle lens, and all those straight lines are going to have to bend somewhere!
    A more accurate picture plane, one that could actually capture a real image without any distortion, would be a sphere, with the eye at the center. Straight lines now map to great circles on the sphere, and whole images, just like the ones your eye sees, can be presented in their entirety.


    But then you can't exactly paste them into your photo album. So you are back to the question of, how do you map a sphere onto a plane?


    Or maybe you could get some funny looking virtual reality googles.

  11. Re:Bottom line... by kavau · · Score: 2, Informative
    Key thing is, buy cameras according to the optical reputation of the brand, not the electronics/digital reputation. 99% of the time things will work out better that way.

    Not always true. Reputable companies sometimes throw cheap stuff at you, too. The camera in question here is a Pentax Optio S, and Pentax certainly has a good reputation in optics (maybe not as good as Nikon, but certainly good enough). The problem with the Optio S is its "revolutionary sliding lens design", which makes the camera as thin as a deck of cards. However, as in world politics, revolutions often introduce a whole new set of problems...

  12. Using Panorama Tools to correct lens distortions by BrunoPostle · · Score: 2, Informative

    I have a couple of examples, both involve correcting perspective at the same time:

    A single photo, corrected

    Two photos stitched, corrected and perspective adjusted

    There is a project to build an easy-to-use front-end for panorama tools: Hugin, it has a Mailing-list, anyone welcome.

    If you just want to batch process individual photos without having to learn Panorama Tools, try this perl-script, it implements everything required to correct barrel distortion (though you have to calibrate your camera first).