File Exchange

## Image segmentation using Otsu thresholding

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

Updated 10 Mar 2010

View Version History

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.

Example:
---------
subplot(221)
X = ind2gray(X,map);
imshow(X)
title('Original','FontWeight','bold')
for n = 2:4
IDX = otsu(X,n);
subplot(2,2,n)
imagesc(IDX), axis image off
title(['n = ' int2str(n)],'FontWeight','bold')
end

------
http://www.biomecardio.com/matlab/otsu.html
-----

### Cite As

Damien Garcia (2020). Image segmentation using Otsu thresholding (https://www.mathworks.com/matlabcentral/fileexchange/26532-image-segmentation-using-otsu-thresholding), MATLAB Central File Exchange. Retrieved .

Laxmidhar prusty

Hoang Ly

Just like multithresh function I think.

Rasika Devi

usha diggi

Thanks for the code and brief explaination

Luqman Subki

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

muthukumaran t

matlab code for luminance level thresholding

Venkat

Jing

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 =...
(mu(end)*w(2:end-1)-mu(2:end-1)).^2./w(2:end-1)./(1-w(2:end-1));

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

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

Samuele

works smoothly...thx ;)

Matteo Niccoli

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

Dalal

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

Fu

Lukas Lansky

Works nice!

##### MATLAB Release Compatibility
Created with R2007b
Compatible with any release
##### Platform Compatibility
Windows macOS Linux