Main Content


Insert markers in image or video



RGB = insertMarker(I,position) insert plus (+) markers into the truecolor or grayscale image I. The function draws markers by overwriting pixel values at the specified positions. The output image RGB is always a truecolor image.

RGB = insertMarker(I,position,marker) inserts markers of the specified marker type marker.

RGB = insertMarker(___,Name=Value) specifies options using one or more name-value arguments in addition to any combination of input arguments from previous syntaxes. For example, MarkerColor="red" specifies to render the inserted position markers in red.


collapse all

Read an image into the workspace.

I = imread("peppers.png");

Insert a plus (+) marker onto the image at specified position.

RGB = insertMarker(I,[147 279]);

Specify the positions, colors, and sizes of four cross (x) markers and insert onto the image.

pos = [120 248; 195 246; 195 312; 120 312];
color = {"red","white","green","magenta"};
RGB = insertMarker(RGB,pos,"x",MarkerColor=color,Size=10);

Display the image.


Input Arguments

collapse all

Input image, specified as an M-by-N-by-3 truecolor or an M-by-N grayscale image.

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

Position of markers, specified as an M-by-2 matrix, where each row is an image coordinate pair of the form [x y], or an M-element vector of one of the points objects listed on the Point Feature Types page. M is the number of markers to insert into the image. The function defines the position of each marker as the [x y] pair of coordinates in the matrix, as the value of the Location property of the corresponding point feature object.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Type of marker, specified as a character vector or string scalar. You can specify the marker type using either the full text name or the corresponding symbol.

Full Text NameSymbol

Data Types: char | string

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.

Example: insertMarker(I,position,Color="yellow") sets the marker color to yellow.

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

Example: insertMarker(I,position,"Color","yellow") sets the marker color to yellow.

Size of the marker in pixels, specified as a scalar in the range [1,Inf).

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Marker color, specified as a short color name, color name, vector of color names, three-column matrix of RGB triplets.

The supported colors table lists RGB intensities in the range [0, 1], but you must specify RGB triplets in the range of your selected data type. For example, if specifying this argument as a matrix of uint8 values, you must convert each intensity value to the range [0, 255]. To convert the listed intensity values to a uint8 data type, use the code uint8(255*intensity), where intensity is an RGB triplet value listed in the table.

You can specify a different color for each marker or one color for all markers. To specify one color for all markers, specify MarkerColor as a color name or an [R G B] vector.

Specify one color for all shapes (or markers)

Short color name or color name



RGB triplet

[1 0 0]1-by-3 grid, with columns labeled r,g,b respectively.

Specify a color for each shape (or marker)

Vector of color names


Three-column matrix of RGB triplets

[1 0 0
 0 1 1
 1 0 1
 1 1 1]
M-by-3 grid, with columns labeled r,g,b respectively.

This table lists the supported marker colors.

Color NameShort NameRGB TripletAppearance
"red""r"[1 0 0]

Sample of the color red

"green""g"[0 1 0]

Sample of the color green

"blue""b"[0 0 1]

Sample of the color blue

"cyan" "c"[0 1 1]

Sample of the color cyan

"magenta""m"[1 0 1]

Sample of the color magenta

"yellow""y"[1 1 0]

Sample of the color yellow

"black""k"[0 0 0]

Sample of the color black

"white""w"[1 1 1]

Sample of the color white

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

Output Arguments

collapse all

Output image, returned as an M-by-N-by-3 truecolor image.

Extended Capabilities

Version History

Introduced in R2013a

expand all