Code covered by the BSD License  

Highlights from
barrel and pincushion lens distortion correction

3.83333

3.8 | 6 ratings Rate this file 136 Downloads (last 30 days) File Size: 586 KB File ID: #37980
image thumbnail

barrel and pincushion lens distortion correction

by

 

31 Aug 2012 (Updated )

I = LENSDISTORT(I, k)corrects for radially symmetric distortions

| Watch this File

File Information
Description

I = LENSDISTORT(I, k)corrects for radially symmetric distortions, where
I is the input image and k is the distortion parameter. lens distortion
can be one of two types: barrel distortion and pincushion distortion.
In "barrel distortion", image magnification decreases with
distance from the optical axis. The apparent effect is that of an image
which has been mapped around a sphere (or barrel). In "pincushion
distortion", image magnification increases with the distance from the
optical axis. The visible effect is that lines that do not go through the
centre of the image are bowed inwards, towards the centre of the image,
like a pincushion [1].

I = LENSDISTORT(...,PARAM1,VAL1,PARAM2,VAL2,...) creates a new image,
specifying parameters and corresponding values that control various aspects
of the image distortion correction. Parameter names case does not matter.

Parameters include:

'bordertype' String that controls the treatment of the image
                    edges. Valid strings are 'fit' and 'crop'. By
                    default, 'bordertype' is set to 'crop'.

'interpolation' String that specifies the interpolating kernel
                    that the separable resampler uses. Valid
                    strings are 'cubic', 'linear' and 'nearest'. By
                    default, the 'interpolation' is set to 'cubic'

'padmethod' string that controls how the resampler
                    interpolates or assigns values to output elements
                    that map close to or outside the edge of the input
                    array. Valid strings are 'bound', circular',
                    'fill', 'replicate', and symmetric'. By
                    default, the 'padmethod' is set to 'fill'

'ftype' Integer between 1 and 4 that specifies the
                    distortion model to be used. The models
                    available are

                    'ftype' = 1: s = r.*(1./(1+k.*r));

                    'ftype' = 2: s = r.*(1./(1+k.*(r.^2)));

                    'ftype' = 3: s = r.*(1+k.*r);

                    'ftype' = 4: s = r.*(1+k.*(r.^2));

                    By default, the 'ftype' is set to 4.

Class Support
-------------
An input intensity image can be uint8, int8, uint16, int16, uint32,
int32, single, double, or logical. An input indexed image can be uint8,
uint16, single, double, or logical.

Examples
--------
  % read image
  I = imread('cameraman.tif');

  % Distort Image
  I2 = lensdistort(I, 0.1);

  % Display both images
  imshow(I), figure, imshow(I2)

References
--------------
[1] http://en.wikipedia.org/wiki/Distortion_(optics), August 2012.

[2] Harri Ojanen, "Automatic Correction of Lens Distortion by Using
  Digital Image Processing," July 10, 1999.

[3] G.Vassy and T.Perlaki, "Applying and removing lens distortion in post
  production," year???

[4] http://www.mathworks.com/products/demos/image/...
  create_gallery/tform.html#34594, August 2012.

Created by Jaap de Vries, 8/31/2012
jpdvrs@yahoo.com

-----------------------------------------------------------------------%

Required Products Image Processing Toolbox
MATLAB
MATLAB release MATLAB 7.14 (R2012a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (16)
18 Mar 2014 Brooke

Does anyone's images get the edges chopped off when using the 'undistortimage' tool? If so how can I fix this to where my whole image is shown and not a cropped version. Thank you!

19 Nov 2013 Sina Tebianian

Thanks Jaap. Yes, my images have pincushion distrotion and should be corrected. I saw that lensdistort(I,k) works well for small pincushion distortions specially for the central part of the image. The edges get the opposite effect of Barrel. I can send you a sample image I started working on as an example. How I can I use the other algorithms?

14 Nov 2013 Jaap de Vries

Sina, do you have an image with radial distortion? barrel or pincushion.

if so, import the image and assign to a variable (e.g., I)

Then aply correction I2 = lensdistort(I, 0.1) play with the 0.1 to get the wanted effect.

Diffrerent algorithms are available if you wish too.

13 Nov 2013 Sina Tebianian

Hi Jaap, I did not quite understand how to correct the distorsion i.e. from a distorted image arrive to the non-distorted one. I appreciate your help.

12 Nov 2013 Bsh kh  
16 Sep 2013 Jaap de Vries

Dank je wel Matthijs, :-)

16 Sep 2013 Alaster McDonach

Many Thanks. Using it to undistort images;Fantastic

26 Aug 2013 Matthijs

For GoPro Hero3 use ftype=3 and k=-0.32. You're welcome :).

02 Aug 2013 piao lin

good,it works,correct the image. wonderful。

18 Apr 2013 MML  
13 Dec 2012 Jaap de Vries

Robert, thank you.
When a distortion is radial, you can apply an inverse correction. I guess this code can do both then. Yes the border correction as of now only works for the default correction function. It was actually one of the harder things to do.

19 Nov 2012 Robert Jacobsen

Very nice code!

It appears that your border correction is intended for the default ftype only.

Regarding Eyal's comment, I think he means that this way of manipulating images is usually thought of as simulating distortion, not removing it.

24 Oct 2012 Jaap de Vries

Thank you Carlos, yes I don't understand Eyal's comment either, I even supplied example files and showed how they work. The distortion models are clearly shown to be axisymetrix, i.e., f(r).

24 Oct 2012 Carlos

Awesome job, i dont understand the last post about creates distortion but does not correct for radially symmetric distortions.

05 Oct 2012 Eyal

The help is misleading.
The file creates distortion but does not correct for radially symmetric distortions.

04 Sep 2012 Jaap de Vries

Please rate my files or leave helpful commenst so I can make improvements.

J.

Updates
31 Aug 2012

8-31-2012 Made some spelling corrections and added an example.pdf file and example images

Contact us