otsu
Image segmentation using Otsu's thresholding
Contents
Download
Syntax
IDX = otsu(I) IDX = otsu(I,N) [IDX,sep] = otsu(...)
Description
IDX = otsu(I,N) segments the array 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. Zero values are assigned to non-finite (NaN or Inf) pixels.
IDX = otsu(I) uses N = 2 (default value).
[IDX,sep] = otsu(...) also returns the value (sep) of the separability criterion within the range [0 1]. Zero is obtained only with arrays having less than N values, whereas one (optimal value) is obtained only with N-valued data.
Notes:
- It should be noticed that the thresholds generally become less credible as the number of classes (N) to be separated increases (see Otsu's paper for more details).
- 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.
Examples
Read the image "clown" from Matlab and segment the picture in 2, 3 and 4 classes.
load clown
Convert the indexed image to intensity (grayscale) image:
imshow(X,map) X = ind2rgb(X,map);
Segment the gray-level image into 2, 3 or 4 classes by using the Otsu's method:
for n = 2:4 IDX = otsu(X,n); figure, imagesc(IDX), axis image off title(['n = ' int2str(n)]) end colormap(gray)



Reference & Information
Otsu N., A threshold selection method from gray-level histogram, IEEE Trans. Syst. Man Cybern. 9:62-66;1979
Otsu's method on Wikipedia.
See also
About the author
Damien Garcia, Eng., Ph.D. Assistant professor, Department of radiology CRCHUM, University of Montreal Hospital Montreal, QC, Canada Damien.Garcia.REMOVE-THIS@BiomeCardio.com