File Exchange

image thumbnail

Thresholding Tool

version 1.6.0.1 (6.21 KB) by

Interactively select intensity level for image thresholding.

4.47368
18 Ratings

37 Downloads

Updated

View License

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

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.

Comments and Ratings (24)

masyitah razi

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

Error using ==> thresh_tool at 46

%defensive programming
error(nargchk(1,3,nargin))
error(nargoutchk(0,2,nargout))
Not enough input arguments. why this?

Cass

Cass (view profile)

Very nice tool! Run smoothly! Thank you!

raju maher

Good

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!

error occured ????
rgbImage=imread('image.jpg');
thresholdvalue=thresh_tool(rgbImage)
??? Undefined function or method 'thresh_tool' for input arguments of type 'uint8'.

xiang fiona

Nice work~Thanks for sharing!

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.

Robert Bemis

Robert Bemis (view profile)

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

David James

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

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?

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?

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.

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)

Nathan Tomlin

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

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

veysel gökhan böcekçi

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

M Rosenbluth

Nice gui.

Sudip Ghosh

This is an excellent tool! Thanks!

piyush jain

Carlos Oliveira

Very useful tool.

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

1.6.0.1

Updated license

1.6

ZIP file corrected

1.4

copyright

1.3

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

1.1

Fix thumbnail for animated GIF

MATLAB Release
MATLAB 7 (R14)

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

» Watch video