4.7

4.7 | 10 ratings Rate this file 294 downloads (last 30 days) File Size: 6.12 KB File ID: #6770

Thresholding Tool

by Robert Bemis

 

21 Jan 2005 (Updated 22 Jun 2009)

Code covered by BSD License  

Interactively select intensity level for image thresholding.

Download Now | 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

The author wishes to acknowledge the following in the creation of this submission:
hline and vline

Required Products Image Processing Toolbox
MATLAB release MATLAB 7 (R14)
Zip File Content  
Other Files license.txt,
thresh_tool.m
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (13)
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);

08 Mar 2005 Carlos Oliveira

Very useful tool.

16 Jan 2006 piyush jain  
07 Apr 2006 Sudip Ghosh

This is an excellent tool! Thanks!

23 May 2006 M Rosenbluth

Nice gui.

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**

09 Aug 2007 veysel gökhan böcekçi  
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'));

19 Jun 2009 Nathan Tomlin

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

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)

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.

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?

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?

Please login to add a comment or rating.
Updates
02 Mar 2009

Fix thumbnail for animated GIF

22 Jun 2009

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

Tag Activity for this File
Tag Applied By Date/Time
threshold level Robert Bemis 22 Oct 2008 07:40:00
gui tool Robert Bemis 22 Oct 2008 07:40:00
bin Robert Bemis 22 Oct 2008 07:40:00
grayscale intensity image segmentation Robert Bemis 22 Oct 2008 07:40:00
threshold level emregul ersan 01 Nov 2008 13:47:44
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com