File Exchange

image thumbnail


version (703 KB) by Jan Neggers
Interactive tool allowing the measurement of distances, radii, and angles in images


Updated 12 Mar 2021

From GitHub

View Version History

View license on GitHub

Editor's Note: This file was selected as MATLAB Central Pick of the Week

# Measure Tool
Measure Tool is a matlab function (measuretool.m) that provides a Graphical User Interface (GUI) that is designed to aid measurements on images.

If an image contains some visible object of known length, for example, a scale bar or a ruler, then the physical size of an area as imaged by a pixel (i.e. the pixel size) can be calibrated. This tool provides tools to perform this calibration (draw a line on the ruler) and then perform measurements on the image:
- Distance: point-point distance
- Caliper: line-point perpendicular distance
- Polyline: multi-point distance
- Spline: smooth multi-point distance (Catmull-Rom interpolated)
- Circle: center and radius
- Angle: line-line intersection angle

The main motivation behind the tool is precision. This is achieved by allowing image magnification changes while measuring. This allows the user to place points precisely using the mouse. Additionally, all measurements can by edited to allow further refinement.

The GUI is reasonably self contained, all code resides in one file: measuretool.m
This file also contains the GUI help, which is available through the GUI itself. See the header of measuretool.m for more info.

The tool has been hosted on the Matlab FileExchange since November 2009, the corresponding website can be found here: Recently, that site is linked to the GitHub repository, which can be found here:

Please let me know (by submitting and issue on GitHub) if you find any bugs or issues, or if you have some nice ideas for improvement.

Cite As

Jan Neggers (2021). Jann5s/measuretool (, GitHub. Retrieved .

Comments and Ratings (63)

Jan Neggers

I think I found the issue, it occurred when you didn't calibrate the image (which is fine). I've pushed a new version with a fix

@Adam Lowery
This feature turned out to be really simple to add, check out the new version (it has a new checkbox in options)

Jan Neggers


I guess that your original comment got replaced by the new one. I still have the error in my mail:

Error in measuretool/output_fun (line 2915 )
B(i).obj(j).val_unit = B(i).obj(j).val_px * B(i).pixelsize(1);

Error in measuretool/save_fun (line 2145 )
mt_data = output_fun ;

Error using uiwait (line 81 )
Error while evaluating UIControl Callback.

So, I'm not sure what is going wrong. When I test the "Save project" is working. I'm guessing there is a bug somewhere which is loosing track of some measurements and when time comes to save them this error occurs. Do you always have this issue? Could you give me some hints as to how to reproduce the issue.

What you could do as a small hack is to add this line under
2904 if ~isfield(A,'obj')
2905 return
2905 end

All the data is already in a structure (A) and the function output_fun() only does some housekeeping to reduce the size of this structure before saving. The assignin command will write the entire structure to your workspace every time output_fun() is called, so when you press "save project" for instance (even if the error occurs just after)

Adam Lowery

This is a very well designed code. I really appreciate how its evolved over each iteration. It would be nice to be able to adjust the color of the shapes/objects independent of previously drawn objects within the image/figure. I noticed that if you adjust the color your object, every other objects adjust to that color as well. This makes segmenting specific features a little harder.


I should add that "Save to Text" does work but extracting the results from a .txt file for further processing is obviously rather tedious…

Markus G

Janos Fuzik

Very helpful, nice design. Thanks a lot!

Jan Neggers

@Valeria and @Rachel, the output was never supposed to be in the selected unit. My idea was that users that are advanced enough to use the output structure can multiply the value in pixels with the pixel size (as explained in the help). However, I consider it highly likely that I'm bad at predicting expectations. So I modified the output to have both, obj(j).val_px and obj(j).val_unit such that users can select which they prefer. Although, obj(j).points will still be given in pixels and you have to multiply yourself with the pixelsize.

Rachel Bernard

I have the same issue with Valeria that the newest Beta version (on Github) outputs the wrong value (in pixels rather than desired unit i.e. mm). Thanks for this program!

longfei jiao

LiShang Lin

how can I run it in matlab 2014?

Valeria Ardizzon

hi, great tool!!
I think (in the new version) that the outputs in A.obj.val are not saved correctly "as displayed in the text box" (I mean, they are in pixel, not in the selected unit).
Anyway, super thank you to you!

Jan Neggers

The new version can be found here:
Warning: this version is in BETA, it needs testing. Please read my previous post for more info.

Jan Neggers


I saw that people are having issues with this tool in combination with newer matlab versions. Then when digging in this now 8 year old code, I felt it could use a refresh.

So, I've written a completely new version. It uses more modern definitions of graphics objects. Additionally, it has completely new click and drag code. This makes the GUI feel more intuitive (I hope), and now there is no longer a dependency on the image processing toolbox.

In general I think the GUI is much nicer now.

However, given all the code is fresh, and I only have matlab 2015a currently installed, I would really like it if one or two of you users would be willing to test-drive it before I publish it. I've tested it as much as I can, but there are over 3000 lines of code, and I'm pretty sure there are still some glaring bugs.

Please send me a message if you want to try the new version.

I will probably upload this new version in the beginning of 2018.

Greets Jan,

Michel Buck

Same here with R2016b. An update would be really nice for a really nice tool

alejandro anaya

Erkan Ozkat

Thank you, John. It is very good application and I have been using regularly. Recently, I have upgraded to Matlab 2017a and I faced with the below error message; when I run your application
%%%%%% Error Message %%%%%%%%%%%%%%%%%

Error using dir
Characters adjacent to a ** wildcard must be file separators.

Error in measuretool>FileBrowse_Callback (line 174)
filestmp = dir([filepath filesep '*' imagetypes{i}]);

Error in gui_mainfcn (line 95)

Error in measuretool (line 41)
gui_mainfcn(gui_State, varargin{:});

Error in>@(hObject,eventdata)measuretool('FileBrowse_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.


I was wondering if you could go through the application again, please,
King regards

Louviot Samuel

Very good tool, But I have several errors :
When I try to open a image this error appears :
Error in gui_mainfcn (line 95)

Error in measuretool (line 41)
gui_mainfcn(gui_State, varargin{:});

Error in>@(hObject,eventdata)measuretool('FileBrowse_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback

James Huth

Thank you John. That worked!

John Clark

James, Ayman, there's an extra wildcard since the original author left wildcards in his imagetypes cell (line 155 of measuretool.m).
To fix, remove the wildcard in line 174 of measuretool.m so that it reads:
filestmp = dir([filepath filesep imagetypes{i}]);

James Huth

Hi - I'm having the same problem as Aymann... error when trying to open image. Tried to fix first "dir" error... couldn't. Any advice? Thank you.

Ayman Saleh

For some reason, whenever I try to upload an image, I keep getting these errors.
Error using dir
Characters adjacent to a ** wildcard must be file separators.

Error in measuretool>FileBrowse_Callback (line 174)
filestmp = dir([filepath filesep '*' imagetypes{i}]);

Error in gui_mainfcn (line 95)

Error in measuretool (line 41)
gui_mainfcn(gui_State, varargin{:});

Error in>@(hObject,eventdata)measuretool('FileBrowse_Callback',hObject,eventdata,guidata(hObject))

Error while evaluating UIControl Callback
Anyone have any idea what I am doing wrong?


It would be really great to get the syntax `measuretool(Img)` such that you do not need to use the file browser to find the file. I would also like to get better documentation with clear synapse and example commands in Matlab promp.


Kealie Goodwin

This is extremely useful. Only reason for 4/5 stars is that it re-plots the image and measurements every time and if you have a lot of measurements (100+), it can bog down a get a little slow.

Kealie Goodwin

This is a wonderful tool and very useful for my application. Is there a way to preserve a zoomed in view, rather than zooming out after each measurement? I'd like to stay zoomed in as I am making many measurements in a small area.


App is not opening perfectly in matlab 2014a. top portions of app is not visible. I cannot load files.

William Currier

Great tool! It has been incredibly helpful for me and very easy to use. It is very accurate and makes measuring a large number of images in a dynamic environment very easy.

I was wondering if it is possible to have something that stores the calibration coordinates to the workspace similar to how the software stores the distance measurements.

So I am thinking there could be a structure that includes the following fields in the first row:

filename = 'name of image'
type = 'calibration'
value = 'distance between the two points'
intensity = '--'
profile = '--'
unit = 'calibration units'
x and y = 'the x or y coordinate for the calibration'

Also, another thing that I have noticed is that if one is measuring a large number of images and re-calibrates halfway through it changes all of the previous measurement values based on this re-calibration. It would be great in my opinion if this was more explicit or optional.

Nguyen Thanh Dong

Thank you very much for this SOFTWARE.
I want to measure size of objects from capturing an image on a microscopy and this software has made my work complete.

Jan Klement

Excelenet for 2D measurements.

Amit Saha

Thank you very much for this great tool. This tool has made my project complete, on machine vision systems. Thank you, thank you so much.

Ilya Belevich

Hi Jan,
thank you for this great work!

I've noticed a small bug: when I delete a measurement the n-numbers of the others are not changed. As result addition of a new measurement produces two measurements with the same n-number.


Really awesome stuff - great interface, great use of cross-hairs for identifying features.

An enhancement idea:
If I have engineering data traces, it would be great to do calibration in 2 directions and then automatically calculate coordinates of points from the origin.


Andrew Lingenfelter

Great App. Just wanted to say thanks!


I would suggest an application for google glass of this tools.


Hi Jan-

Great tool! I noticed the measurement displays with only two decimal places. Can you build in an option that allows you to select how many significant digits you wish to display the measurement? Also, is it possible to make an option to display the x and y coordinates of the distance as well?

Thanks for posting this app. It is very helpful!

Jan Neggers

Thank you Jie, you are correct, I forgot to add .bmp to the list of options, and your fix is perfect. I will update the tool accordingly.


I think this is a great tool.
But I have a doubt. Does this toolbox work for .bmp file? When I try to browse .bmp files, there seems to be error. Pictures I took in microscope is usually .bmp file.
I simply add "*.bmp"(in correct form) in your .m file No. 156 & 160 line. It seems work good. Do you think I'm doing right? Wish to hear from you.

Justin Blaber

Thanks for the great tool!


Great tool, easy to use and works well. The ability to turn off image processing tool box requirement is a very nice touch


I haven't used this much yet, but it looks great. Is there any simple way to reduce the height of the GUI so that it doesn't extend below my task bar though?


It is very simple and its use is intuitive. I love it and use it all the time.


Marcelo Soto Thompson


This is really a good work. Well done.

Moatasem chehaiber

Great job


How to get the real length & breadth of an image in millimeters?
i need it to calculate pixels/mm for my text extraction project


great program, thanks


Amazing tool!
So useful. Thanks a lot.

Civil Eng

I am getting errors whatever I click

Civil Eng

Selcuk Fidan

ling li


Jan Neggers

Hi Jakub, i'll see what I can do, this is a little bit more complex as one might think since the intensity is stored in pixels which are discrete by nature, and the measurement lines do not follow pixel locations per se, so some interpolation is required.


Hi Jan,

Great tool. Would it be possible to add a feature to measure mean intensity of signal within line length.


GANESH Prabhakar

superb tool ..Thank u

Jan Neggers


If you don't have the function imline, then you probably have a matlab version older then 2009b, or maybe the function is provided by the image processing toolbox.


I am getting an error when I try to calibrate (see below). Can you offer any suggestions? I have an jpeg radiographic image.

??? Undefined function or method 'imline' for input arguments of type 'double'.

Error in ==> measuretool>Calibrate_Callback at 435
h = imline(Data.gca,[u(1) v(1) ; u(2) v(2)]);

Error in ==> gui_mainfcn at 96

Error in ==> measuretool at 41
gui_mainfcn(gui_State, varargin{:});

Error in ==> @(hObject,eventdata)measuretool('Calibrate_Callback',hObject,eventdata,guidata(hObject))

??? Error while evaluating uicontrol Callback

Jason Tolentino

great program in analyzing TEM images. I wanted to know how difficult is it to save the data because I would like to do size distribution analysis on the saved data.


Hi Jan,
thanks for this nice tool. However, I have a question: I have gray scale TEM images in tif format. Your tool seems to convert them to RGB. I had a very short glance at the code, and think it is related to the call of imagesc in line 324. It might also be related to the specific format of my tif file. It would be nice, if you could comment on this.

Prashanth Ravindran

this GUI is excellent. It can measure the distance between 2 points, perpendicular distance of a point from a line, angle between 2 lines. This GUI is fantastic.

Jan Neggers

I've posted an update to fix some minor bugs, awaiting review at the moment.

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

Community Treasure Hunt

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

Start Hunting!