OTSU - Global image thresholding/segmentation using Otsu's method

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. Zero values are assigned to non-finite (NaN or Inf) pixels.

IDX = OTSU(I) uses two classes (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 data having less than N values, whereas one (optimal value) is obtained only with N-valued arrays.

Contents

Example #1:

subplot(121)
X = imread('saturn.png');
imshow(X)
title('Original','FontWeight','bold')
subplot(122)
IDX = otsu(X);
imagesc(IDX), axis image off
title('Otsu-thresholded','FontWeight','bold')
colormap(gray)

Example #2:

load clown
subplot(221)
X = ind2rgb(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
colormap(gray)

Notes

It should be noticed that the thresholds generally become less relevant 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.

Reference

Otsu N, A Threshold Selection Method from Gray-Level Histograms, IEEE Trans. Syst. Man Cybern. 1979;9:62-66.

See also

graythresh, otsuthresh

About the author

Damien Garcia, Eng., Ph.D.
INSERM researcher
Creatis, University of Lyon, France

website: BioméCardio