Main Content

imcontour

Create contour plot of image data

Description

imcontour(I) draws a contour plot of the grayscale image I, choosing the number of levels and the values of levels automatically. imcontour automatically sets up the axes so their orientation and aspect ratio match the image.

imcontour(I,levels) specifies the number, levels, of equally spaced contour levels in the plot.

example

imcontour(I,V) draws contour lines at the data values specified in vector V. The number of contour levels is equal to length(V).

imcontour(x,y,___) uses the vectors x and y to specify the image x- and y coordinates.

imcontour(___,LineSpec) draws the contours using the line type and color specified by LineSpec. Marker symbols are ignored.

[C,h] = imcontour(___) returns the contour matrix, C, and the contour patches, h, that are drawn onto the current axes.

Examples

collapse all

Read and display a grayscale image.

I = imread("rice.png");
imshow(I)

Figure contains an axes object. The hidden axes object contains an object of type image.

Create a contour plot of the image with three contour levels.

imcontour(I,3);

Figure contains an axes object. The axes object contains an object of type contour.

Input Arguments

collapse all

Grayscale image, specified as an m-by-n matrix.

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

Number of contour levels, specified as a numeric scalar.

Value of contour levels, specified as a numeric vector with length greater than or equal to two. Use V = [v v] to compute a single contour at level v.

Image x values, specified as one of the following:

  • 2-element numeric vector of the form [xmin xmax] — Image extent in the x direction.

  • n-element numeric vector — x-coordinate of each column.

Image y values, specified as one of the following:

  • 2-element numeric vector of the form [ymin ymax] — Image extent in the y direction.

  • m-element numeric vector — y-coordinate of each row.

Line style and color, specified as a character vector or string scalar containing a line style specifier, a color specifier, or both.

Example: "--r" specifies red dashed lines

These two tables list the line style and color options.

Line StyleDescriptionResulting Line
"-"Solid line

Sample of solid line

"--"Dashed line

Sample of dashed line

":"Dotted line

Sample of dotted line

"-."Dash-dotted line

Sample of dash-dotted line, with alternating dashes and dots

Color SpecifierDescriptionAppearance

r

red

Sample of the color red

g

green

Sample of the color green

b

blue

Sample of the color blue

c

cyan

Sample of the color cyan

m

magenta

Sample of the color magenta

k

yellow

Sample of the color yellow

k

black

Sample of the color black

w

white

Sample of the color white

Output Arguments

collapse all

Contour matrix, returned as a matrix with two rows. The matrix is defined according to the ContourMatrix property of the Contour object, h.

Contour patches, returned as a Contour object.

Version History

Introduced before R2006a

See Also

Functions

Properties