This example shows how to warp an indexed image over a nonuniform surface. This example uses a curved surface centered at the origin.

Read an indexed image into the workspace.

[I,map] = imread('forest.tif');

Create the surface. First, define the x- and y-coordinates of the surface. This example uses arbitrary coordinates that are unrelated to the indexed image. Note that the size of the coordinate matrices X and Y do not need to match the size of the image.

[X,Y] = meshgrid(-100:100,-80:80);

Define the height Z of the surface at the coordinates given by (X,Y).

Z = -(X.^2 + Y.^2);

Warp the image over the surface defined by the coordinates (X,Y,Z).

figure
warp(X,Y,Z,I,map);

Explore the warped image interactively using the rotate and data cursor tools.

Warp the image over the surface whose height is equal to the intensity of the image I. Specify the number of graylevels.

figure
warp(I,I,128);

Note that the x- and y-coordinates of the surface were not specified in the call to warp and thus default to the image pixel indices. Explore the warped image interactively using the rotate and data cursor tools.

X — Indexed image 2-D array of real numeric values

Indexed image, specified as a 2-D array of real numeric values.
The values in X are an index into map,
an n-by-3 array of RGB values.

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

map — Colormap n-by-3 array of real numeric values

Colormap, specified as an n-by-3 array of
real numeric values. Each row specifies an RGB color value. When map is
type single or double, values
must be in the range [0, 1].

Data Types: single | double | uint8

I — Intensity image 2-D array of real numeric values

Intensity image, specified as a 2-D array of real numeric values.

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

n — Number of grayscale levels positive integer

Number of grayscale levels, specified as a positive integer.

Data Types: double | uint8 | uint16 | logical

BW — Binary image 2-D array of logical values

Binary image, specified as a 2-D array of logical values.

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

RGB — Truecolor image m-by-n-by-3 array of
real numeric values

Truecolor image, specified as an m-by-n-by-3
array of real numeric values.

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

Z — Height of surface 2-D array of real numeric values

Height of surface, specified as a 2-D array of logical values.
When Z is not specified, the surface is flat
with a uniform height of 0.

You can also select a web site from the following list:

How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.