Main Content


Correct fisheye image for lens distortion



J = undistortFisheyeImage(I,intrinsics) removes lens distortion for image I and returns the result as image J.

[J,camIntrinsics] = undistortFisheyeImage(I,intrinsics) also returns a cameraIntrinsics object, which corresponds to a virtual pinhole camera.

[___] = undistortFisheyeImage(___,interp) specifies the interpolation method, interp, using the preceding syntaxes.


[___] = undistortFisheyeImage(___,Name,Value) specifies one or more Name,Value pair arguments. Unspecified properties have their default values.


collapse all

Remove lens distortion from a fisheye image by detecting a checkboard calibration pattern and calibrating the camera. Then, display the results.

Gather a set of checkerboard calibration images.

images = imageDatastore('calibrationImages');

Detect the calibration pattern from the images. The 'PartialDetections' Name-Value argument is set to true by default allowing detection of partial checkerboards.

[imagePoints,boardSize] = detectCheckerboardPoints(images.Files, 'HighDistortion', true);

Generate world coordinates for the corners of the checkerboard squares.

squareSize = 20; % millimeters
worldPoints = generateCheckerboardPoints(boardSize,squareSize);

Estimate the fisheye camera calibration parameters based on the image and world points. Use the first image to get the image size.

I = readimage(images,10); 
imageSize = [size(I,1) size(I,2)];
params = estimateFisheyeParameters(imagePoints,worldPoints,imageSize);

Remove lens distortion from the first image I and display the results.

J1 = undistortFisheyeImage(I,params.Intrinsics);
title('Original Image (left) vs. Corrected Image (right)')

Figure contains an axes. The axes with title Original Image (left) vs. Corrected Image (right) contains an object of type image.

J2 = undistortFisheyeImage(I,params.Intrinsics,'OutputView','same', 'ScaleFactor', 0.2);
title('Output View with low Scale Factor')

Figure contains an axes. The axes with title Output View with low Scale Factor contains an object of type image.

Input Arguments

collapse all

Input image, specified as an M-by-N-by-3 truecolor or M-by-N 2-D grayscale image. The input image must be real and nonsparse.

Data Types: single | double | int16 | uint8 | uint16 | logical

Fisheye intrinsic camera parameters, specified as a fisheyeIntrinsics object.

Interpolation method to use on the input image, specified as 'bilinear', 'nearest' , or 'cubic'.

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: 'ScaleFactor',2 sets the scale factor to increase the zoom in the camera view.

Size of the output image, specified as either 'same', 'full', or 'valid'.

Scale factor for the focal length of a virtual camera perspective, in pixels, specified as a scalar or an [sx sy] vector. Specify a vector to scale the x and y axes individually. Increase the scale to zoom in the perspective of the camera view.

Output pixel fill values, specified as the comma-separated pair consisting of 'FillValues' and scalar or 3-element vector. When the corresponding inverse-transformed location in the input image lies completely outside the input image boundaries, you use the fill values for output pixels. When you use a 2-D grayscale input image, FillValues must be a scalar. When you use a truecolor image, FillValues can be a scalar or a 3-element vector of RGB values.

Output Arguments

collapse all

Undistorted image, returned as an M-by-N-by-3 truecolor or M-by-N 2-D grayscale image.

Data Types: single | double | int16 | uint8 | uint16 | logical

Undistorted intrinsics of a virtual camera, returned as a cameraIntrinsics object. The camIntrinsics object represents a virtual pinhole camera. You can use this object with the pinhole model calibration workflow functions. These intrinsics are for a camera that has a perspective that produces the undistorted image.


  • The Computer Vision Toolbox™ calibration algorithm uses the fisheye camera model proposed by Scaramuzza [1].


[1] Scaramuzza, D., A. Martinelli, and R. Siegwart. "A Toolbox for Easy Calibrating Omnidirectional Cameras." Proceedings to IEEE International Conference on Intelligent Robots and Systems, (IROS). Beijing, China, October 7–15, 2006.

Introduced in R2017b