LEGO® MINDSTORMS® and Technic®MINDSTORMS® EV3/NXTMINDSTORMS SensorsLEGO® technical dataLDrawMiscellaneous LEGO®LEGO® & PhotographyPanoramic PhotographyPhoto GalleryHome

 

 

 

    Correction of image distortion and perspective

    Step by step description of a method to correct image distortion and perspective using Panorama Tools and PTgui

    Photographed with Coolpix 990 + wide angle adapter WC-E24

    There are two common problems when shooting architectural images:

    • lines are curved because of lens distortion (zooms generally exhibit barrel distortion at wide angle position
    • they are slanted if your camera is not perfectly horizontal.

    Both defaults can be corrected in a single (though lengthy!) operation using Panorama Tools and PTgui. The procedure described below seems long and complicated, but this is because I tried to detail each step.

    Read also "Correcting Barrel Distortion" by Helmut Dersch.

    June 2002 update : Erik Krause has written a tutorial on a slightly different method to correct distortion, see it here.

    What do I need ?

    • a working installation of Panorama Tools with PTstitcher (I used version 2.6) : get it here.
    • PTgui : get it here.
    • a photo-editing program will be useful to crop and rotate your images if necessary.

    Step 1

Source images tab:

  1. Click on Add button, select your image and press OK
  2. Click Next


    Step 2

Lens settings tab:

  1. Select Normal lens type
  2. Insert Focal of your lens or its horizontal field of view - exact value is not critical
  3. Set all lens corrections parameters (a, b and c) to 0.001 (default value). Of course if you have better startup values from a previous work or lens calibration, use these values
  4. Click Next


    Step 3

Panorama settings tab:

  1. Select Rectilinear projection
  2. Set field of view to about 20% more than fov of your original image
  3. ... and image dimensions 20% bigger than original dimensions
  4. Select your prefered image format
  5. Click Next (no cropping needed)


    Step 4

Image parameters tab:

  1. Set initial orientation angles of your image (yaw, pitch and roll) to 0
  2. Click Next


    Step 5



 

Control points tab: (CP =control point)

  1. Verify that CP type is "align horizontally". As you have only one image, this should be the default option. The image will be transformed such that the horizontal distance of the CP is minimized. This CP type define points that should be on the same vertical line in the final panorama.
  2. Auto-add : if you use only mouse to position your cursor over CP, you should not use auto-add as the CP will be validated as soon as you click on the second image, and it is easy to move accidentally. I use a mixed mouse/keyboard strategy: position mouse approximatively and fine tune using keyboard (use Alt-arrows to move, Alt-enter to mark CP). Auto-add is then fine...
  3. On left image, select a point at bottom of a clearly defined vertical line (3a), then on right image mark a point at top of the SAME vertical (3b).
  4. Do the same between bottom and middle of another vertical (4a, 4b). (this will help to fix barrel distortion). Go on with a few vertical lines scattered on the image (I used 7 CP on this one)
  5. Click Next


    Step 6

Optimizer tab:

  1. Check Advanced interface
  2. Check the optimisation of Roll and Pitch (Roll is the angle of the camera around lens axis, Pitch is the angle of this axis with horizontal plane)
  3. Check all three lens distortion parameters (if you have few vertical lines in your image and couldn't set enough CP, check only b parameter and set a=c=0 in lens settings tab
  4. Click Run Optimizer


    Step 7

Optimizer results:

After a short time, this windows opens. If you made no mistake while placing your CPs you should have a "This is good" message or even better.

Click OK

Note: this kind of optimisation problem generally has a lot of solutions, don't worry if you get different values for a/b/c when you modify startup values. Getting consistent values requires extensive lens calibration (see for example Big Ben's Panorama Tutorials)

 


    Step 8


Now come back to image parameters tab:

  1. The thumbnail has been updated to reflect pitch and roll correction (but not lens distortion correction). You may verify that your photo fits in the corrected image. If - as it is the case here - the camera was heavily tilted, it will be cropped and you have to enlarge generated image.
  2. To do that, go to Panorama Settings tab. If your photo doesn't fit in vertical direction, increase panorama height.
  3. If it doesn't fit in horizontal direction, increase horizontal field of view (Panorama Tools always resize image so that given hfov spans all horizontal size). As your image gets shrunk when you increase hfov, you may want to increase horizontal size too.
  4. As you modify panorama settings you may control your image using PTgui panorama editor (enable/disable it in <Window> menu)


    Step 9

Last step... go to Create Panorama tab, and click on Create button... That's it, you only have to crop image.

    Download these elements to try yourself:


    Original image


    Raw result


    Cropped result

    PTgui script

    PTstitcher (optimizer) script

    PTstitcher (create panorama) script

    For more details and examples, goto part 2

LEGO® MINDSTORMS® and Technic®MINDSTORMS® EV3/NXTMINDSTORMS SensorsLEGO® technical dataLDrawMiscellaneous LEGO®LEGO® & PhotographyPanoramic PhotographyPhoto GalleryHome