View License

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

» Watch video

Highlights from
Image segmentation using Otsu thresholding

5.0 | 6 ratings Rate this file 138 Downloads (last 30 days) File Size: 3.53 KB File ID: #26532 Version: 1.4
image thumbnail

Image segmentation using Otsu thresholding


Damien Garcia (view profile)


29 Jan 2010 (Updated )

OTSU(I,N) segments the image I into N classes by means of Otsu's N-thresholding method.

| Watch this File

File Information

IDX = OTSU(I,N) segments the image I into N classes by means of Otsu's N-thresholding method. OTSU returns an array IDX containing the cluster indices (from 1 to N) of each point.
IDX = OTSU(I) uses two classes (N=2, default value).
[IDX,sep] = OTSU(I,N) also returns the value (sep) of the separability criterion within the range [0 1]. Zero is obtained only with data having less than N values, whereas one (optimal value) is obtained only with N-valued arrays.

If I is an RGB image, a Karhunen-Loeve transform is first performed on the three R,G,B channels. The segmentation is then carried out on the image component that contains most of the energy.
    load clown
    X = ind2gray(X,map);
    for n = 2:4
      IDX = otsu(X,n);
      imagesc(IDX), axis image off
      title(['n = ' int2str(n)],'FontWeight','bold')

See also:

MATLAB release MATLAB 7.5 (R2007b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (11)
17 Nov 2016 usha diggi

Thanks for the code and brief explaination

Comment only
01 Jun 2016 Luqman Subki

In the example provided, what is 'X', anyone?

Comment only
26 Oct 2015 muthukumaran t

matlab code for luminance level thresholding

Comment only
25 Apr 2013 Venkat

Venkat (view profile)

09 Jul 2012 Jing

Jing (view profile)

Thanks a lot for the code!
I just have a question: in the n=2 case, what's the meaning for the following code? I tried to derive the equation, but could not make it. Would you please explain a bit? Thanks!!

sigma2B =...

21 Jan 2012 Jamuna Jayashri Mahalingam

I am geting this error...How do I correct it?

Undefined function or method 'otsu' for input arguments of type 'uint8'.

Comment only
11 Feb 2011 Samuele

works smoothly...thx ;)

13 Oct 2010 Matteo Niccoli

It has worked for me very nicely. I like to run it in a while loop that breaks when sep starts decreasing.

10 Jul 2010 Dalal

Dalal (view profile)

i am trying to segment the image of signature
is it possible to apply the same code ?
thank you

Comment only
28 Apr 2010 Fu

Fu (view profile)

11 Mar 2010 Lukas Lansky

Works nice!

31 Jan 2010 1.1

New screenshot.

28 Feb 2010 1.2

RGB images are now analyzed in the gray, R, G and B scales.

04 Mar 2010 1.3

The segmentation for RGB image has been improved: a KLT is performed and we keep the component of highest energy.

10 Mar 2010 1.4

Minor modifications

Contact us