Main Content


Transform image to bird's-eye view



J = transformImage(birdsEye,I) transforms the input image, I, to a bird’s-eye-view image, J. The OutputView and ImageSize properties of the birdsEyeView object, birdsEye, determine the portion of I to transform and the size of J, respectively.


collapse all

Create a bird's-eye-view image from an image obtained by a front-facing camera mounted on a vehicle. Display points within the bird's-eye view using the vehicle and image coordinate systems.

Define the camera intrinsics and create an object containing these intrinsics.

focalLength = [309.4362 344.2161];
principalPoint = [318.9034 257.5352];
imageSize = [480 640];

camIntrinsics = cameraIntrinsics(focalLength,principalPoint,imageSize);

Set the height of the camera to be about 2 meters above the ground. Set the pitch of the camera to 14 degrees toward the ground.

height = 2.1798;
pitch = 14;

Create an object containing the camera configuration.

sensor = monoCamera(camIntrinsics,height,'Pitch',pitch);

Define the area in front of the camera that you want to transform into a bird's-eye view. Set an area from 3 to 30 meters in front of the camera, with 6 meters to either side of the camera.

distAhead = 30;
spaceToOneSide = 6;
bottomOffset = 3;

outView = [bottomOffset,distAhead,-spaceToOneSide,spaceToOneSide];

Set the output image width to 250 pixels. Compute the output length automatically from the width by setting the length to NaN.

outImageSize = [NaN,250];

Create an object for performing bird's-eye-view transforms, using the previously defined parameters.

birdsEye = birdsEyeView(sensor,outView,outImageSize);

Load an image that was captured by the sensor.

I = imread('road.png');
title('Original Image')

Transform the input image into a bird's-eye-view image.

BEV = transformImage(birdsEye,I);

In the bird's-eye-view image, place a 20-meter marker directly in front of the sensor. Use the vehicleToImage function to specify the location of the marker in vehicle coordinates. Display the marker on the bird's-eye-view image.

imagePoint = vehicleToImage(birdsEye,[20 0]);
annotatedBEV = insertMarker(BEV,imagePoint);
annotatedBEV = insertText(annotatedBEV,imagePoint + 5,'20 meters');

title('Bird''s-Eye-View Image: vehicleToImage')

Define a location in the original bird's-eye-view image, this time in image coordinates. Use the imageToVehicle function to convert the image coordinates to vehicle coordinates. Display the distance between the marker and the front of the vehicle.

imagePoint2 = [120 400];
annotatedBEV = insertMarker(BEV,imagePoint2);

vehiclePoint = imageToVehicle(birdsEye,imagePoint2);
xAhead = vehiclePoint(1);
displayText = sprintf('%.2f meters',xAhead);
annotatedBEV = insertText(annotatedBEV,imagePoint2 + 5,displayText);

title('Bird''s-Eye-View Image: imageToVehicle')

Input Arguments

collapse all

Object for transforming image to bird's-eye view, specified as a birdsEyeView object.

Input image, specified as a truecolor or grayscale image. The OutputView property of birdsEye determines the portion of I to transform to a bird's-eye view.

I must not contain lens distortion. You can remove lens distortion by using the undistortImage function. In high-end optics, you can ignore distortion.

Output Arguments

collapse all

Bird’s-eye-view image, returned as a truecolor or grayscale image. The ImageSize property of birdsEye determines the size of J.

Extended Capabilities

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

Version History

Introduced in R2017a

See Also