Want to read Slashdot from your mobile device? Point it at m.slashdot.org and keep reading!

 



Forgot your password?
typodupeerror
×
AMD

Correcting Lens Aberrations in Digital Photography? 67

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?"
This discussion has been archived. No new comments can be posted.

Correcting Lens Aberrations in Digital Photography?

Comments Filter:
  • Tutorial (Score:4, Funny)

    by L. VeGas ( 580015 ) on Tuesday June 03, 2003 @02:53PM (#6107800) Homepage Journal
    1. Grip each eyeball firmly between your middle fingers and thumbs.

    2. With your forefingers at 9:00 (left) and 3:00 (right), press firmly against each eye. Distortion should now be minimized.

    3. Should blindness occur, trim fingernails and repeat with alternate eyeballs.
  • Seems to me... (Score:5, Informative)

    by Lendrick ( 314723 ) on Tuesday June 03, 2003 @02:57PM (#6107841) Homepage Journal
    ...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.
    • Re:Seems to me... (Score:3, Informative)

      by Mprx ( 82435 )
      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.
      • Re:Seems to me... (Score:3, Informative)

        by Lendrick ( 314723 )
        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.
        • Do one square per pixel of source image, colored squares (no texture)... and use the raw data (RGB), with the pixel grid in place. That is, don't use the combined RGB values; each pixel should be some saturation of one of red, green, or blue. Antialiasing and filtering, then, should give you the optimal (combined RGB) image, either before or after distorting.
    • How would we have worked it out without you!
    • Firstly, forget about graph paper. It is already common practise in photography to examine the properties of a camera's lens and viewfinder using standard test images such as this [66.227.34.3] (don't use this actual image though, it is a photograph itself, not actually the source image).

      I think the poster already has an idea how to solve the problem, he mentions digital mappings, but the point is that he doesn't want to go to the effort of coding if it has been done before.
      • Re:Seems to me... (Score:4, Insightful)

        by nomel ( 244635 ) <turd&inorbit,com> on Tuesday June 03, 2003 @06:26PM (#6110054) Homepage Journal
        Firstly, forget about graph paper.


        Huh? Graph paper would do a MUCH better job at finding the lenses flaws, and make it fairly simple to correct them...that picture you have would barely do any good at all...just on the parts where there was detail. Even then, that would be insanely hard to implement in software compared to a grid. It might be better at finding focus or something...but thats not the point. The graph paper would show you exactly how the lense was deformed at practically every point on the lense (depending on density of the lines of course). All you would have to do to fix it would be straighten out the lines. I don't really see how that picture you posted could be used to find lense distortion...it just doesn't have enough detail. What is it specifically for?
      • No, not that image. That's an image used to determine the fidelity of a digital camera. Higher megapixels (or higher-fidelity chips like the Foveon) will resolve higher-detail features.

        A grid, such as that generated by taking a picture of graph paper, is exactly what you need to correct for barrel distortions and the like.
  • AMD logo? (Score:3, Interesting)

    by kworthington ( 678559 ) <kworthington.gmail@com> on Tuesday June 03, 2003 @03:02PM (#6107874) Homepage
    I'm just curious why there's an AMD logo for this edition of ask /.
    • I am wondering the same thing? Is it an error with the slashdot posting system or is it an error by the writer. We may never know.
      • Is it an error with the slashdot posting system or is it an error by the writer.

        IIRC I posted the story with "Graphics" as the topic. However, "AMD" is the first topic in the list so I strongly suspect an oversight by the editor (not to be blasphemous or anything...)

  • PanoTools (Score:5, Informative)

    by ugglan ( 21001 ) on Tuesday June 03, 2003 @03:02PM (#6107877)

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

    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 [unimelb.edu.au]

  • google says... (Score:5, Informative)

    by tchuladdiass ( 174342 ) on Tuesday June 03, 2003 @03:03PM (#6107882) Homepage
    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/
    • You're right about the patent thing. Ipix aparently has a patent [albury.net.au] that they are using on Quicktime QTVR [albury.net.au] and panotools [leeds.ac.uk]. more info [virtualproperties.com] warning - these links seem a bit old; I wonder what the progress has been. These are pretty simple algorithms (not trivial to implement, though) and are exactly the type of patents I hate... argh...
  • Photoshop options (Score:3, Informative)

    by cgenman ( 325138 ) on Tuesday June 03, 2003 @03:08PM (#6107925) Homepage
    I know, I know, not freeware. Yet everyone seems to have a copy.

    a creative pro [creativepro.com] article about correcting barrel distortion, and one at Fred Miranda [fredmiranda.com].

  • Nothing new here (Score:5, Interesting)

    by themo0c0w ( 594693 ) on Tuesday June 03, 2003 @03:11PM (#6107958)

    This has been a problem in traditional photography for some time. Distortion for wide angle shots always occurs for any wide angle shot -- try a 28mm lense sometime and see for yourself.

    Special lenses do exist to correct for this. However, the are very expensive. Generally, only architecture photographers and other professionals have them.

    You'll probably want a better lens anyway for doing any sort of quality photography. Oh, and as for fixing it with a filter, good luck. Its not as easy as just applying a transform as the person with the graph paper suggests. The warping depends on distance from the lens.

    • The warping depends on distance from the lens.

      If some physicist can explain that one to me, I'll eat my shorts. (Note, we're not talking about blurring, we're talking about warping.)
      • Re:Nothing new here (Score:3, Informative)

        by hamjudo ( 64140 )
        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.

        • Almost...spherical distortion is a long standing problem, and it DOES depend on the subject's distance from the lens (this is why spherical abberation is generally fixed in microscope lenses). If you take a close up picture (of a face for example) with a lens with bad distortion at close distances (like a wide angle lens), objects that are just a little closer to the lens than others in the frame (like the tip of the person's nose) will seem a great deal closer as a result of the distortion (creating a pin
      • Like the other guy said, you change focus and zoom...and since lense shape is static...you moving lenses away or to the detector/film. So I gues it does directly have to do with distance.
    • Distortion for wide angle shots always occurs for any wide angle shot

      True. However, my film SLR has no noticeable distortion at 35mm. With my pocket digital, the issue is clearly the inferior lens, and not the fundamental limitations you're mentioning.

      You'll probably want a better lens anyway for doing any sort of quality photography.

      I'm well aware that it's impossible to get high-quality pictures from an ultra-compact camera. I chose this particular camera, however, because it's easy to carry around

  • Hmmmm, I wonder (Score:2, Insightful)

    by shaka999 ( 335100 )
    Not the most computationally efficient method but I wonder if you could do this with povray.

    Use the picture as an image map on a sphere or cylinder. Keep adjusting the frame and object size until the lines look straight. Make sure the object is self illuminating and you don't use external light sources...

    Hmmmm, seems like it might work....
    • Ok, I thought about this some more and the sphere or cylinder would have the opposite effect. But, I think the idea of using a 3d renderer is still sound.

      Basically build a custom lens in the program and view the image through that lens. The lens would straighten the lines....

      Err I think it could..
      • Doing it with the sphere or cylinder would work, if you could stick the texture to the inside of the object, on the opposite side (on the back inside part, instead of the front outside part). I don't have any experience with applying textures to 3d objects and stuff, so this is purely from a logical point of view.
  • DLT (Score:5, Informative)

    by MountainLogic ( 92466 ) on Tuesday June 03, 2003 @03:16PM (#6108002) Homepage
    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?)

  • VIPS & NIP (Score:5, Informative)

    by Yarn ( 75 ) on Tuesday June 03, 2003 @03:26PM (#6108096) Homepage
    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 [soton.ac.uk].

    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).
    • VIPS looks very interesting, but I couldn't find any tools for applying distortions to a picture, except for rather trivial ones such as scaling and rotating. Am I missing something? Are the convolution tools more powerful than I think they are?
      • It has rubbersheet distortion, I'd imagine that would do the job just fine.
      • Re:VIPS & NIP (Score:2, Informative)

        by jcupitt65 ( 68879 )
        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 wel
        • VIPS & NIP are wonderful. Thank you!

          Unfortunately, I can't this rubbersheet plugin anywhere, neither in the rpms from the site, nor the source package I have compiled up. Both nip 7.8.8. I can find the rubbersheet batch stuff, but nothing that looks like a binary plugin. Am I doing something stupid, or is it really not there?

          Also, is there a page where all the nifty scripts/plugins that people have made can be found? If there isn't, do you think there should be? ;)
          • Oh dear, they should be. I'll check.
          • Thanks for your kind words (blush).

            The RPMs should have the rubbersheet stuff inside already (complied into the library).

            I've added an extra download for the binary for just the plugin, in case you build from source. Check out the vips-7.8 download page again.

            There are some extras in the "extras" bit at the top of the website. nip has only been launched properly for 6 months, so there's no public repository yet.
  • photoshop plugin (Score:5, Informative)

    by foniksonik ( 573572 ) on Tuesday June 03, 2003 @03:38PM (#6108249) Homepage Journal

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

    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.
  • by hamjudo ( 64140 ) on Tuesday June 03, 2003 @03:57PM (#6108454) Homepage Journal
    Intel's Open CV [intel.com].

    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 [oreillynet.com]. Note how the URLs inside the article are mostly out of date.

  • by Hell O'World ( 88678 ) on Tuesday June 03, 2003 @04:09PM (#6108563)
    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.

    • 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.

      Your statement is certainly true for ultra-wide angle lenses (below 24mm focal length, 35mm equivalent). A moderate wide-angle lens (24-35mm, 35mm equivalent) of good quality should not show any significant distortions, according to this article [ephotozine.com]. I am actually more interested in the range above

  • http://www.frc.ri.cmu.edu/~hpm/project.archive/ro b ot.papers/2000/ARPA.MARS.reports.00/Report.0001.ht ml

    This describes a piece of software called FLATFISH that can correct the type of distortion you're seeing.

    I'll warn you, it can be a bit tempermental until you get used to working with it, and it's not meant for the faint of heart. But I've personally used it for camera calibration on a robot using a webcam for vision, and I can say that it does work pretty well. It will very likely give you the tech
  • Best stuff is here: http://www-2.cs.cmu.edu/afs/cs.cmu.edu/user/rgw/ww w/TsaiCode.html
  • I have a couple of examples, both involve correcting perspective at the same time:

    A single photo, corrected [blackfish.org.uk]

    Two photos stitched, corrected and perspective adjusted [blackfish.org.uk]

    There is a project to build an easy-to-use front-end for panorama tools: Hugin [sourceforge.net], it has a Mailing-list [email-lists.org], anyone welcome.

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

  • Have you checked Tabaware [tawbaware.com]? The author of Pixelzap and others, offers a ton of info on post-processing digital images to do neat tricks, including perspective correction for panorama assembly, etc.
  • I know digital pornography inflicts a lot of eye strain, but I never thought that there are specific correcting lens that deal with this sort or eyes strain... oh wait..
  • Dave Dyer wrote a photoshop plugin called LensDoc [andromeda.com] for this purpose for Andromeda Software. I haven't personally used it, but the sample results look pretty nice, and the guy definitely knows what he's doing. Check out some of his other stuff [andromeda.com] as well.
  • Extended Depth Imaging is definately whats called for here. Basically, you stick a filter on the front of the lens that is comprised of mostly transparent grid lines. Then you right software that searches for the grid lines in the image, and maps the source image using the distorted grid lines *contained* within each picture. High-end systems generally have a piece of hardware stuck on the camera that
    does it for you prior to dumping to the storage unit. This technique is used extensively in robotics to

He has not acquired a fortune; the fortune has acquired him. -- Bion

Working...