View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Add an ROI toolbar to your figure

4.5 | 2 ratings Rate this file 10 Downloads (last 30 days) File Size: 622 KB File ID: #41120 Version: 1.3
image thumbnail

Add an ROI toolbar to your figure


Yi Sui (view profile)


04 Apr 2013 (Updated )

This function adds an ROI toolbar to your figure.

| Watch this File

File Information

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.


Roi Rool, Imdisp, and Draggable inspired this file.

This file inspired Enhanced Dicom Viewer and Imstack.

Required Products Image Processing Toolbox
MATLAB release MATLAB 7.14 (R2012a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (13)
06 Jan 2017 Muhammad Muinul Islam

%Edited by Muinul Islam

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

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

Comment only
07 May 2015 arnold

arnold (view profile)

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

Comment only
13 Aug 2014 arnold

arnold (view profile)

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.

Comment only
29 Sep 2013 arnold

arnold (view profile)


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


Comment only
02 Sep 2013 isen

isen (view profile)

02 Sep 2013 isen

isen (view profile)

Stunning work! really helps a lot, thank you!

Comment only
16 Jul 2013 Yi Sui

Yi Sui (view profile)

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

Comment only
16 Jul 2013 mercy

mercy (view profile)

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!

Comment only
15 Jul 2013 Yi Sui

Yi Sui (view profile)

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

Comment only
15 Jul 2013 Yi Sui

Yi Sui (view profile)

please try

let me know if it works.

Comment only
15 Jul 2013 mercy

mercy (view profile)

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);

Comment only
11 Apr 2013 Yi Sui

Yi Sui (view profile)

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

Comment only
04 Apr 2013 arnold

arnold (view profile)

Thanks, nice function!

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

04 Apr 2013 1.1

bug fixes

11 Apr 2013 1.2

Live update for histogram and x-y plot.
Display ROI area in ROI info textbox.
Display distance for line.
Work when there are multiple images in one figure.
Bug fixes.

18 Jul 2013 1.3

Add a slider to adjust the number of bins in histogram

Contact us