Main Content

undistortFisheyeImage

Correct fisheye image for lens distortion

Description

example

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.

example

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

Examples

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);
figure
imshowpair(I,J1,'montage')
title('Original Image (left) vs. Corrected Image (right)')

J2 = undistortFisheyeImage(I,params.Intrinsics,'OutputView','same', 'ScaleFactor', 0.2);
figure
imshow(J2)

title('Output View with low Scale Factor')

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 Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

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.

Tips

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

References

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

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Version History

Introduced in R2017b

expand all