View License

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

» Watch video

Highlights from
Thresholding Tool

4.7 | 17 ratings Rate this file 43 Downloads (last 30 days) File Size: 6.21 KB File ID: #6770 Version:
image thumbnail

Thresholding Tool


Robert Bemis (view profile)


21 Jan 2005 (Updated )

Interactively select intensity level for image thresholding.

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

| Watch this File

File Information

THRESH_TOOL launches a GUI (graphical user interface) for thresholding an intensity input image, IM. IM is displayed in the top left corner. A colorbar and IM's histogram are displayed on the bottom. A line on the histogram indicates the current threshold level. A binary image is displayed in the top right based on the selected level. To change the level, click and drag the line. The output image updates automatically.
There are two ways to use this tool.
Mode 1 - nonblocking behavior:
THRESH_TOOL(IM) launches GUI tool. You can continue using the MATLAB Desktop.Since no results are needed, the function does not block execution of other commands.
THRESH_TOOL(IM,CMAP) allows the user to specify the colormap, CMAP. If not specified, the default colormap is used.
THRESH_TOOL(IM,CMAP,DEFAULTLEVEL) allows the user to specify the default threshold level. If not specified, DEFAULTLEVEL is determined by GRAYTHRESH. Valid values for DEFAULTLEVEL must be consistent with the data type of IM for integer intensity images: uint8 [0,255], uint16 [0,65535], int16 [-32768,32767].
x = imread('rice.png');
%no return value, so MATLAB keeps running
Mode 2 - blocking behavior:
LEVEL = THRESH_TOOL(...) returns the user selected level, LEVEL, and MATLAB waits for the result before proceeding. This blocking behavior mode allows the tool to be inserted into an image processing algorithm to support an automated workflow.
[LEVEL,BW] = THRESH_TOOL(...) also returns the thresholded binary output image, BW.

x = imread('rice.png');
lev = thresh_tool(x) %MATLAB waits for GUI tool to finish
See also colormap, graythresh, im2bw.


Hline And Vline inspired this file.

This file inspired Cell Area, Manual Thresholding Tool, and Demos From Image Processing Webinar 2006.

Required Products Image Processing Toolbox
MATLAB release MATLAB 7 (R14)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (23)
29 Aug 2016 Edmund Pickering

Great tool. I use this regularly. Thanks for the fantastic work.

24 Aug 2016 Hirak Mazumdar

Error using ==> thresh_tool at 46

%defensive programming
Not enough input arguments. why this?

Comment only
16 Jun 2016 Cass

Cass (view profile)

Very nice tool! Run smoothly! Thank you!

21 Mar 2016 raju maher


16 Apr 2014 Trenton

Hey Robert Bemis, I was also experiencing the inverted text bug. I followed the steps listed in the link you provided and it corrected itself. Thanks for the insight!

Also this tool is fantastic!

Comment only
15 Apr 2013 Rajesh Gothwal

error occured ????
??? Undefined function or method 'thresh_tool' for input arguments of type 'uint8'.

18 Apr 2011 xiang fiona

Nice work~Thanks for sharing!

30 Aug 2010 Janelle Shane

Registered just so I could say thanks for sharing this very very useful program. Works great, and has saved me a ton of time.

31 Mar 2010 Robert Bemis

Robert Bemis (view profile)

David James, and anyone else who sees upside-down text, please see if this applies.

Comment only
31 Mar 2010 David James

Excellent tool, just one odd effect appears when running the gui in Matlab 2009a, where the text appears flipped vertically and horizontally

27 Aug 2009 pkenned Kennedy

Hi Robert, thank you for this program, it is most helpful. I have a slight problem however, when I import a 16 bit dicom file the input image on the left appears with the jet colormap. I changed line 103 to gray but now I just get a black image. Do i need to edit dislayrange somehow?

26 Jun 2009 Charles Griffin

I'm just beginning to learn image segmentation for a Masters thesis. My thesis is on remote sensing and I was told that thresholding was the way to go on this thesis. Do you have any suggestions that could narrow my research in a more directed path?

22 Jun 2009 Robert Bemis

Robert Bemis (view profile)

Nathan and others, thanks for all the feedback. Some users have been tripped up by the requirement that the input must be an intensity image. RGB color is not supported. I will update the function to for this at the beginning and stop immediately with a more helpful error message.

Comment only
19 Jun 2009 Nathan Tomlin

I apologize for cluttering the comments - didn't read carefully (and wish I could edit previous posts...). Like Benjamin said, it doesn't work if you input an RGB image. Just add:

if ndims(im) == 3
im = rgb2gray(im);

19 Jun 2009 Nathan Tomlin

didn't work for me - I got the same errors as listed above

Comment only
20 Sep 2007 Benjamin Benson

Neat tool and nice gui. For all guys having problems with assignment error: You should load a grayscale image:
x = rgb2gray(imread('img.png'));

09 Aug 2007 veysel gökhan böcekçi

10 May 2007 Naveen Kumar

x= imread('a.jpg');
lev = thresh_tool(x,[1.0 1.0 0])

??? Assignment has more non-singleton rhs dimensions than non-singleton

Error in ==> ind2rgb at 35
rout(:,:,1) = r;

Error in ==> thresh_tool>im2rgb at 118
rgb = ind2rgb(ind,full_map);

Error in ==> thresh_tool at 110
rgb = im2rgb(im,full_map);


Comment only
23 May 2006 M Rosenbluth

Nice gui.

07 Apr 2006 Sudip Ghosh

This is an excellent tool! Thanks!

16 Jan 2006 piyush jain

08 Mar 2005 Carlos Oliveira

Very useful tool.

25 Jan 2005 ivan scardanzan

>> thresh_tool(X);
??? Assignment has more non-singleton rhs dimensions than non-singleton

Error in ==> ind2rgb at 35
rout(:,:,1) = r;

Error in ==> subimage>parse_inputs at 150
cdata = im2uint8(ind2rgb(varargin{1},varargin{2}));

Error in ==> subimage at 43
[x,y,cdata] = parse_inputs(varargin{:});

Error in ==> thresh_tool at 49

>> X=X(:,:,1);
>> thresh_tool(X);

02 Mar 2009 1.1

Fix thumbnail for animated GIF

22 Jun 2009 1.3

Added graceful error message if input not intensity image as required.

12 Jan 2010 1.4


02 Feb 2010 1.6

ZIP file corrected

01 Sep 2016

Updated license

Contact us