Loading [MathJax]/extensions/tex2jax.js
MRaster examples 22.0.0.0
Image Processing Library
All Files Functions Pages
geomTfrm_LensDistortion.cpp File Reference

Read an image, correct it for radial lens discortion, and write out the corrected image. More...

Go to the source code of this file.

Detailed Description

Read an image, correct it for radial lens discortion, and write out the corrected image.

Author
Mitch Richling https://www.mitchr.me
Details


The geomTfrmRevRPoly() method uses a radial polynomial transform. This method may be used to reproduce the behavior of Imagemagick's barrel distortion transformation. In Imagemagick the following terminology and constraints are used:

  • (X, Y) is the image center for both T & S
  • A, B, C, & D are constants
  • A+B+C+D=1 – if you don't provide D it will be computed

This is all put together on the command line something like this:

-distort Barrel "A B C D X Y"

We can demonstrate the similar behavior between Imagemagick & this example program like this:

  • Make test images
    make test_images ./test_images.exe
  • Compute the new image with imagemagik
    rm test_images_mcgrid_fimg.tiff magick test_images_mcgrid.tiff -background Green -virtual-pixel Background -interpolate Bilinear -filter point -distort barrel "0.0 -0.0160 0.0" test_images_mcgrid_fimg.tiff start test_images_mcgrid_fimg.tiff
  • Compute the new image with MRaster
    make geomTfrm_LensDistortion ./geomTfrm_LensDistortion.exe test_images_mcgrid.tiff mv geomTfrm_LensDistortion.tiff test_images_mcgrid_fmr.tiff start test_images_mcgrid_fmr.tiff
  • Use compare aginst the two imgages
    magick compare -metric mae test_images_mcgrid_fmr.tiff test_images_mcgrid_fimg.tiff out.tiff start out.tiff
  • Subtract the two images
    magick test_images_mcgrid_fmr.tiff test_images_mcgrid_fimg.tiff -compose Mathematics -define compose:args='0,1,-1,0' -composite out.tiff start out.tiff

Note the images are not identical, but they are very close.

Definition in file geomTfrm_LensDistortion.cpp.