File Exchange

image thumbnail

Automatic Thresholding

version 1.0 (1.26 KB) by

How to find a good default threshold value?

6 Ratings



No License

Dhanesh Ramachandram posted on same algorithm, march 2003.

 This iterative technique for choosing a threshold was developed by Ridler and Calvard . The histogram is initially segmented into two parts using a starting threshold value such as 0 = 2B-1, half the maximum dynamic range.

 The sample mean (mf,0) of the gray values associated with the foreground pixels and the sample mean (mb,0) of the gray values associated with the background pixels are computed. A new threshold value 1 is now computed as the average of these two sample means. The process is repeated, based upon the new threshold, until the threshold value does not change any more.
(quote from

New feature from the m-file of Dhanesh Ramachandram:
- one does not have to rescale one's image to a uint array. This algorithm works for negative intensities, for example.

vImage = Image(:);
[n xout]=hist(vImage, <nb_of_bins>);
threshold = isodata(n, xout)

You get a (hopefully relevant) threshold for your image.

Comments and Ratings (7)


 too bad


Not too bad. I found the following error on line 27:
mat = sum(count(T_i:end) .* intensity(T_i:end) ) ./ sum(count(T_i:end));

The calculations should run from, T_i + 1 : end

what's <nb_of_bins>); ?

hanno walter

perfect for me

Farry anto

not good,too bad.

Senes Yin

So Simple!

MATLAB Release
MATLAB 6.5 (R13)

Inspired by: Automatic Thresholding

Inspired: Ridler-Calvard image thresholding

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video