FUNCTION REFERENCE

undistortImage

Correct lens distortion in an image.

Correct lens distortion in an image.

Syntax

J = undistortImage(I, intrinsics)

Syntax

J = undistortImage(I, intrinsics, interp)

Syntax

[J, camIntrinsics] = undistortImage(___, 'OutputView', view, 'FillValues', fill)

I is M-by-N or M-by-N-by-3 (double, single, logical or an integer class; J has the class of I); intrinsics is a cameraIntrinsics or cameraParameters object. Each pixel (u, v) of J is normalized with the intrinsics of J, distorted (radial k1..k3, tangential p1, p2, as in worldToImage), mapped back with K and sampled from I with interp 'linear' (default), 'nearest' or 'cubic'. Samples outside the pixel centres of I get FillValues (default 0; a scalar or one value per channel). OutputView 'same' (default) keeps the size of I; 'full' is the whole-pixel box around the undistorted border of I; 'valid' is the largest such box with no fill pixels. camIntrinsics is a cameraIntrinsics for J: the same focal lengths and skew, the principal point moved by the whole-pixel offset of the view, ImageSize = size of J and no distortion.

Example

c = cameraIntrinsics([800 790], [322 238], [480 640], 'RadialDistortion', [-0.12 0.05]); J = undistortImage(ones(480, 640), c); size(J)   % [480 640]

Example

c = cameraIntrinsics([800 790], [322 238], [480 640], 'RadialDistortion', [-0.12 0.05]); [J, n] = undistortImage(ones(480, 640), c, 'OutputView', 'full'); n.ImageSize   % larger than [480 640]

Differences from MATLAB: fisheye (cameraIntrinsicsKB) cameras are not supported; the 'full' and 'valid' boxes are aligned to whole pixels of the 'same' view.

These are the engine’s help pages. Each page keeps its compatibility notes. File operations are unavailable in the browser.