Image segmentation using Otsu's thresholding
IDX = otsu(I) IDX = otsu(I,N) [IDX,sep] = otsu(...)
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.
- 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.
Read the image "clown" from Matlab and segment the picture in 2, 3 and 4 classes.
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)
Otsu N., A threshold selection method from gray-level histogram, IEEE Trans. Syst. Man Cybern. 9:62-66;1979
Otsu's method on Wikipedia.
Damien Garcia, Eng., Ph.D. Assistant professor, Department of radiology CRCHUM, University of Montreal Hospital Montreal, QC, Canada Damien.Garcia.REMOVE-THIS@BiomeCardio.com