Main Content

setColor

(Not recommended) Set color used to draw ROI object

setColor is not recommended. With the new ROIs, set the value of the Color property instead. For more information, see Version History.

Description

setColor(h,color) sets the color used to draw the ROI object h.

example

Examples

collapse all

Display an image. Draw a polygon on the image, specifying the location of five vertices.

imshow("gantrycrane.png")
h = impoly(gca,[188,30; 189,142; 93,141; 13,41; 14,29]);

Closed polygon drawn in blue over an image.

Set the color of the polygon to yellow.

setColor(h,"yellow");

Polygon color changed to yellow.

Input Arguments

collapse all

ROI object, specified as an imellipse, imfreehand, imline, impoint, impoly, or imrect object.

ROI color, specified as an RGB triplet, a color name, or a short color name.

You can specify any color using an RGB triplet. An RGB triplet is a 3-element row vector whose elements specify the intensities of the red, green, and blue components of the color. The intensities must be in the range [0, 1].

You can specify some common colors by name as a string scalar or character vector. This table lists the named color options and the equivalent RGB triplets.

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

A rectangle colored pure red

"green""g"[0 1 0]

A rectangle colored pure green

"blue""b"[0 0 1]

A rectangle colored pure blue

"cyan" "c"[0 1 1]

A rectangle colored pure cyan

"magenta""m"[1 0 1]

A rectangle colored pure magenta

"yellow""y"[1 1 0]

A rectangle colored pure yellow

"black""k"[0 0 0]

A rectangle colored black

"white""w"[1 1 1]

A rectangle colored white

Here are the RGB triplets for the default colors that MATLAB® uses in many types of plots.

RGB TripletAppearance
[0 0.4470 0.7410]

A rectangle colored medium blue

[0.8500 0.3250 0.0980]

A rectangle colored reddish-orange

[0.9290 0.6940 0.1250]

A rectangle colored dark yellow

[0.4940 0.1840 0.5560]

A rectangle colored dark purple

[0.4660 0.6740 0.1880]

A rectangle colored light green

[0.3010 0.7450 0.9330]

A rectangle colored light blue

[0.6350 0.0780 0.1840]

A rectangle colored dark red

Example: "r"

Example: "green"

Example: [0 0.4470 0.7410]

Version History

Introduced in R2008a

collapse all

R2018b: setColor is not recommended

Starting in R2018b, a new set of ROI objects replaces the existing set of ROI objects. The new objects provide more functional capabilities, such as face color transparency. The new classes also support events that you can use to respond to changes in your ROI such as moving or being clicked. Although there are no plans to remove the old ROI objects at this time, switch to the new ROIs to take advantage of the additional capabilities and flexibility. For more information on creating ROIs using the new ROI functions, see Create ROI Shapes.

To set the color of the new ROIs, set the value of the Color property.

Update Code

Update all instances of setColor.

Discouraged UsageRecommended Replacement

This example creates an ROI and uses setColor to specify the color of the ROI.

imshow("cameraman.tif");
h = imrect(gca,[10 10 100 100]);
setColor(h,"yellow");

Replace the ROI with the equivalent new ROI object. Then, delete the call to setColor and set the value of the Color property of the ROI.

imshow("cameraman.tif");
h = drawrectangle(gca,"Position",[10 10 100 100]);
h.Color = "yellow"

See Also

|