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.
X = ind2gray(X,map);
for n = 2:4
IDX = otsu(X,n);
imagesc(IDX), axis image off
title(['n = ' int2str(n)],'FontWeight','bold')