Main Content


Get color used to draw ROI object

getColor is not recommended. Using the new ROIs, retrieve the color of the ROI by accessing the value of Color property instead. For more information, see Compatibility Considerations.


color = getColor(h) gets the color used to draw the ROI object h.

Input Arguments

collapse all

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

Output Arguments

collapse all

RGB color value, returned as a 3-element numeric vector.

Version History

Introduced before R2006a

collapse all

R2018b: getColor 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 retrieve the color of the new ROIs, access the value of the Color property of the ROI.

Update Code

Update all instances of getColor.

Discouraged UsageRecommended Replacement

This example creates an ROI and uses getColor to retrieve the color of the ROI.

h = imrect(gca,[10 10 100 100]);
rgb = getColor(h)

Here is equivalent code, replacing the old ROI with the new ROI object and then accessing the value of the Color property of the ROI.

h = drawrectangle(gca,'Position',[10 10 100 100]);
rgb = h.Color