View License

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

» Watch video

Highlights from
Thresholding an image

4.8 | 13 ratings Rate this file 168 Downloads (last 30 days) File Size: 31 KB File ID: #29372 Version: 1.2
image thumbnail

Thresholding an image


Image Analyst (view profile)


12 Nov 2010 (Updated )

Interactively threshold an image. Make a binary image.

| Watch this File

File Information

This program takes a color or monochrome image and lets the user interactively/manually threshold the monochrome image, or a single color band of a color image, via sliders to set the maximum and minimum thresholds. The thresholded image is a binary image that can be used as a mask image for other images. The pixels in the thresholded range are shown in the middle image as a binary image (black/white), and the original image pixels are shown masked in the left image (gray scale or color). Inputs are the low and high thresholds to start with and the image file name or image matrix. The program returns the threshold values and the last color band that was used to select the threshold. The image can be of type integer (uint8, uint16, etc.) or floating point (single, double).

Required Products Image Processing Toolbox
MATLAB release MATLAB 8.5 (R2015a)
MATLAB Search Path
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (21)
14 Feb 2017 Suchita Kanekar

how to change the path of image

08 Jan 2017 aimi shaharuddin

19 Nov 2016 Adnan Ibrahim

Dear Image Analyst,
This tool is very impressive. May I know which paper u followed for the implementation of this code. Thank you

Comment only
07 Nov 2016 Ali Sultan

Does this work with Matlab R2013a?

Comment only
29 Oct 2016 savita sharma

26 Oct 2016 Adrin Johnson

Excellent work. Is it possible not to show the GUI and just returning the max and min values?

Comment only
25 Oct 2016 Adrin Johnson

28 Sep 2016 Burce Atac Mogol

You should think of preparing a MOOC on image analysis. I will definitely buy it. Thanks..

Comment only
16 Aug 2016 Pradeep Bhaskar

I see your comments in questions posed by others and always they are very helpful. Voting up your answers.

27 Jul 2016 Chanukya

20 Jul 2016 Mandar

Mandar (view profile)

17 Jun 2016 RoBo

RoBo (view profile)

It works really fine, very helpful. Thank you very much.

29 Aug 2015 Ashfaq Ahmed

I have a question,

How can we can we perform accurate edge detection for grayscale images using adaptive detection schemes? I am not talking to use conventional edge thresholding schemes.

1. How it can perform thresholding to removes noise as well.
2. How it can adaptively threshold for 0-255 at each pixel without converting into binary image?
I want to check the performance on edges in images with lot of details.
Kindly elaborate with example.

Comment only
28 Dec 2014 helwan ghgs


17 Nov 2014 MechtEngineer

1. Good layout.
2. GUI does exactly what it claims to do.
3. Almost unbelievable - here is an example of well-commented code. I find the lack of good commenting in code appalling these days. To all programmers: comment your code - it will help you or another user use it down the track, and will often help you structure your code logically when composing it in the first place!

21 Dec 2013 Usama Farooq


09 Sep 2013 Amit Nambiar

Amit Nambiar (view profile)

Thank you for this wonderful tutorial. It really helped me a lot to understand the concept of thresholding in detail and also the matlab codes are wonderful.

Thanks a lot Sir!

28 Jul 2011 Bryson

Bryson (view profile)

Sorry, Sean de, do you mind mentioning how to fix this issue. Which Set(..) in threshold.m should I turn off ?

Comment only
12 Nov 2010 Sean de

Sean de (view profile)

I have 2009b and the 'monitorpositions' option is available.

I found that in the demo_script leaving the set(..) the way you have it works fine and then turning off the set in threshold.m makes it a perfect size. It was this way before too, I could see the figure load set up and look good, then expand to be multiple times my screen width on that call to set().

Anyway, excellent demo! Definitely useful for beginners to understand thresholding.

12 Nov 2010 Image Analyst

Image Analyst (view profile)

Sean, I got to admit I didn't test it on a system with two monitors. The MonitorsPosition seems to be new with R2010b (at least they call it "new" in the 2010b help) so if I put that in it won't work for anyone with older versions. I had considered the Mathworks recommended "maxfig" but I wanted this to be standalone and not require any other code to be downloaded. If you have a fix that will work with all versions, I'd like to see it, and may build it in.

Comment only
12 Nov 2010 Sean de

Sean de (view profile)

The call to:
set(gcf, 'Position', get(0,'Screensize')); % Enlarge figure to full screen.

Blows the figure up on to the point of being way too big to do anything on dual monitors since the screen size is returned as the size of both. The root property 'MonitorPositions' has the individual sizes of the primary and secondary monitors.

Comment only
06 May 2015 1.1

Updated to work with R2015a.

06 May 2015 1.2

Changed description slightly

Contact us