View License

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

» Watch video

Highlights from
Bradley local image thresholding

4.9 | 7 ratings Rate this file 44 Downloads (last 30 days) File Size: 207 KB File ID: #40854 Version: 1.4
image thumbnail

Bradley local image thresholding


Jan Motl (view profile)


18 Mar 2013 (Updated )

A fast an well performing local image thresholding method.

| Watch this File

File Information

The brief idea of the algorithm is that every image's pixel is set to black if its brightness is T percent lower than the average brightness of the surrounding pixels in the window of the specified size, otherwise it is set to white. The detail description of the algorithm is available at:
Derek Bradley, Gerhard Roth (2005). Adaptive Thresholding Using the Integral Image. Retrieved from
The advantage of this method is that the binarized images are subjectively almost as good as from Sauvola's method but the calculation is two times faster than Sauvola's method. Sauvola’s method calculates local mean and local variance, while Bradley’s method calculates just local mean. And because the variance can be calculated using following formula for variance:

  Var(X) = E(X^2) – [E(X)]^2,

the calculation of variance reuses the result from the calculation of the local mean (E(X))^2 and just calculates E(X^2). And that takes the same amount of time as calculation of the local mean. Since calculation of local mean and variance is the most time consuming operation performed by these two methods, Bradley’s method is effectively two times faster than Sauvola’s method. A brief comparison of Bradley’s and Sauvola’s method is available at a blog:

Altun Nazmi (2010). Adaptive (Local) Thresholding For AForge.NET. Retrieved from

The calculation of the local mean is performed with integral image method in constant time regardless of the kernel size.

Examples of real word applications are: bar-code scanners, license plate registration.

MATLAB release MATLAB 6.5 (R13)
MATLAB Search Path
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (12)
19 Jan 2017 Max Fedorchuck

Thanks for sharing!

29 Jul 2016 Tolentee

Does the code apply to 3D images??

Comment only
20 Jul 2016 Mandar

Mandar (view profile)

14 Jul 2016 Gabor

Gabor (view profile)

Thank you so much!
All your set of adaptive thresholding scripts is amazing.
Great work. It's very appreciated.

16 Dec 2015 Henry Kricancic

Hi Jan, is this function based on this paper -- "Adaptive thresholding using the integral image" from 2007 by Bradley and Roth?



Comment only
19 Apr 2015 Jan Motl

Jan Motl (view profile)

Hi, Gunshi. You are right. I fixed the code. And thanks for letting me know!

Comment only
19 Apr 2015 gunshi gupta

19 Apr 2015 gunshi gupta

Hi, this code is really useful, along with all the other binarisation methods!
I just had one doubt though, in the bradley default parameters, which is supposed to be 3 in length, the list is as follows:
optargs={[15 15] 10 0 'replicate'}
this seems like its of length four to me, am i missing something?
or is the T value supposed to be a list as such [10,0]?

Comment only
11 Dec 2014 Michael scheinfeild

excellent code help binarize image

17 Feb 2014 haem

haem (view profile)

05 Jun 2013 Jan Motl

Jan Motl (view profile)

You can try to increase the size of the sliding window. Don't be afraid to increase the windows size to hundreds to hundreds pixels - the window should be bigger than the biggest symbol in the image.

Or you can try the post-processing step from Yanowitz and Bruckstein's binarization method:

Basically it looks at the edge of each foreground object. And if the average gradient along the edge is small, it concludes that it's false foreground object and deletes the object.

Comment only
04 Jun 2013 Max Neudecker

This method works quite well for binarizing my samples!
Note: I found that, depending on the grayvalue variations, a lot of background pixels are wrongly segmented as foreground. However, masking with another binary image, binarized e.g. with Otsu's threshold (function graythresh), remedied this.

01 Apr 2013 1.1

Fixed typo in function description, expanded the package description.

26 Jun 2013 1.2

Added reference to the author's article.

19 Apr 2015 1.3

Fixed the default parameters.

19 Apr 2015 1.4

Fixed the default parameters.

Contact us