File Exchange

image thumbnail

Add an ROI toolbar to your figure

version (622 KB) by Yi Sui
This function adds an ROI toolbar to your figure.


Updated 18 Jul 2013

View Version History

View License

This function adds an ROI toolbar to your figure.
The ROIs are created using matlab buid-in class imroi.

addRoiToolbar: Add an ROI toolbar to the current figure.
addRoiToolbar(h): Add an ROI toolbar to the figure with a handle h.

Example 1:
load mri;
Example 2 (Multiple images):
load mri;

Now draw some ROIs,and right click on one of them, you will see more functions in a context menu, such as:
* change color
* histogram
* x-y plot
* delete

Thanks to the "draggable" made by Francois Bouffard, you can drag around the textbox of ROI info.

imdisp is a nice tool to display multiple images in one figure, written by Oliver Woodford

see also: imroi, imrect, imellipse, imfreehand, imline.

Cite As

Yi Sui (2021). Add an ROI toolbar to your figure (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (14)

Karolina Popowska

Thank You!!! That's what I was looking for!

%Edited by Muinul Islam

hcm= unique(cell2mat(hcm)); Replace this line by

hcm= unique([hcm{:}]);


too bad it doesn't seem to work under 2014b or 2015a anymore.


Hi, another idea: You offer XY Plot for a line but it would also make sense to offer an xy-plot for a selected rectangle... plot the cumulative sum (column-wise, i.e.). This is a feature I use most often with ImageJ, would be great to have in Matlab because there is currently no quick way to do it.



got some more suggestions of features you might wanna add:
- the capability to simply copy a ROI, that'd be very useful!
- it would be great if one could save all ROIs and load them again on a different image
- create a cell or struct with all the ROIs (size, position, mean values etc.). This would be great for evaluating the ROIs with some code




Stunning work! really helps a lot, thank you!

Yi Sui

Just check the help of imroi
You can get the position using
pos = getPosition(h)
where h is the handle of an imroi object.


Thank You! I realized the solution was that i had to double click the image i was interested in before selecting the roi tool. Another question is does this function allow me to get the x and y data points of the roi. I would like to be able to have the same roi show up on another image in the same position. Thanks!

Yi Sui

addRoiToolbar takes figure handles,
So you can use
where h is the handle of the figure you want to add the toolbar on.

Yi Sui

please try

let me know if it works.


Hello, I am trying to use this in a GUI with multiple axes. However the function only works on the most recently opened gui figure but i would like it to work on all the figures. How do i do this?
% --- Executes just before image_processing_July9 is made visible.
function image_processing_July9_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to image_processing_July9 (see VARARGIN)

% Choose default command line output for image_processing_July9
handles.output = hObject;

% set(handles.plot_Bmode,'Visible','off');
set(handles.edit_gamma,'String', sprintf('%4.0f%', get(handles.gamma_slider,'Value')));
set(handles.edit_transparency,'String', sprintf('%4.0f%', get(handles.transparency_slider,'Value')));
% Update handles structure
guidata(hObject, handles);

% UIWAIT makes image_processing_July9 wait for user response (see UIRESUME)
% uiwait(handles.figure1);

Yi Sui

arnold, thank you for your feedback.
I updated it to support the live update of histogram.


Thanks, nice function!

Is there a way you could add a live update for a plot or histogram?

MATLAB Release Compatibility
Created with R2012a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired by: imdisp, ROIRool, draggable

Inspired: imstack, Enhanced Dicom Viewer

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!