Code covered by the BSD License  

Highlights from
Thresholding Tool

4.71429

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

Thresholding Tool

by

 

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
Description

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].
 
Example
x = imread('rice.png');
thresh_tool(x)
%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.

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

Acknowledgements

Hline And Vline inspired this file.

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

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 (19)
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!

15 Apr 2013 Rajesh Gothwal

error occured ????
rgbImage=imread('image.jpg');
thresholdvalue=thresh_tool(rgbImage)
??? 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

David James, and anyone else who sees upside-down text, please see if this applies.
http://www.mathworks.com/support/solutions/en/data/1-91JU4U/?solution=1-91JU4U

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

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.

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);
end
thresh_tool(im)

19 Jun 2009 Nathan Tomlin

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

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
subscripts.

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

**WHAT SHOULD B DONE TO RESOLVE THIS PROBLEM**

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

X=imread('abc.jpg');
>> thresh_tool(X);
??? Assignment has more non-singleton rhs dimensions than non-singleton
subscripts.

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
subimage(im,full_map)

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

Updates
02 Mar 2009

Fix thumbnail for animated GIF

22 Jun 2009

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

12 Jan 2010

copyright

02 Feb 2010

ZIP file corrected

Contact us