File Exchange

image thumbnail

Gray image thresholding using the Triangle Method

version 1.1 (2.8 KB) by

Computes a threshold the Triangle method.



View License

The Triangle method is due to Zack (Zack GW, Rogers WE, Latt SA (1977), "Automatic measurement of sister chromatid exchange frequency", J. Histochem. Cytochem. 25 (7): 741–53.

 A line is constructed between the maximum of the histogram at b on the gray level axis and the lowest (or highest depending on context) value a on the gray level axis where the histogram is significantly larger than 0. The distance L normal to the line and between the line and the histogram is computed for all values from a to b. The level where the distance between the histogram and the line is maximal is the threshold value (level). This technique is particularly effective when the object pixels produce a weak peak in the histogram.

Comments and Ratings (10)

What the main Ref to cite this method


Image Analyst

Image Analyst (view profile)

Threshold is misspelled at Threshnold in legend. Demo doesn't run because second line of comment doesn't have a % at the beginning of the line. Once that was corrected, it was fine.

There are a couple of assumptions that can change the end result. One is that the histogram has one tail longer than the other and that the threshold has to be on the long tail side. The other is the definition of the end point of a histogram tail. In the code, this is set to 10000 (i.e. tails end when there are less than 10000 pixels in the corresponding histogram bin). Depending on the size of the image, this might not be an optimum choice.

Jan Motl

Jan Motl (view profile)

It's giving different threshold than triangle method in ImageJ applied to the same image.

Jan Motl

Jan Motl (view profile)

Image Analyst

Image Analyst (view profile)

Including a screenshot of a bar chart of a histogram with a vertical red bar where the histogram gets thresholded would be helpful for people to understand what they'd be downloading.


ula? (view profile)

Image Analyst

Image Analyst (view profile)

This is a very useful and practical way to do thresholding. It may not be based on any theory, but in practice it's one of the best methods for thresholding a skewed histogram.

One way to improve this submission would be to include a little demo program to call it that would read in a standard MATLAB demo image (such as the cameraman), display it and its histogram, draw a line on the histogram where the threshold level is calculated, and then finally display the binarized image. I had to write all this myself.



A demo file was included.

MATLAB Release
MATLAB 7.5 (R2007b)

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

» Watch video