View License

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

» Watch video

Highlights from

Join the 15-year community celebration.

Play games and win prizes!

» Learn more

5.0 | 4 ratings Rate this file 37 Downloads (last 30 days) File Size: 2.86 KB File ID: #29764 Version:
image thumbnail



Brett Shoelson (view profile)


17 Dec 2010 (Updated )

Performs LOCAL Otsu thresholding on an image, with a user-specified blocksize.

| Watch this File

File Information

Performs LOCAL Otsu thresholding on an image; user can specify blocksize. Facilitates the threshold-segmentation of images with uneven illumination, without the need for background normalization.
SYNTAX: B = thresholdLocally(A,blksz,varargin)
THRESHOLDLOCALLY processes an image, calling graythresh on LOCAL blocks in an image. This facilitates easy thresholding of images with uneven background illumination, for which global thresholding is inadequate. Uses the Image Processing Toolbox function BLOCKPROC (R2009b).
A: Any image (or path/name of an image) suitable for processing with im2bw()
BLKSZ: (Optional) Block size of A, for determination of Otsu thresholding using graythresh(). In the form or [M,N]. Default is as determined by BESTBLK.
1) Any P-V pair accepted by BLOCKPROC.
2) FudgeFactor: a scalar value by which to multiply the local value returned by graythresh.

B: Output image
img = imread('rice.png');
thresholded = thresholdLocally(img);


This file inspired Segment Tool: An Interactive Gui For Segmenting Images.

Required Products Image Processing Toolbox
MATLAB release MATLAB 7.11 (R2010b)
Other requirements Requires Image Processing Toolbox, R2009b or later.
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (7)
14 Jun 2016 jia zheng  
15 Dec 2015 Brett Shoelson

Brett Shoelson (view profile)

There's no paper to steer you to, except for the same one cited in the <graythresh> doc. I simply used the architecture of blockproc, and called graythresh (Otsu's method) on each local block.

Comment only
13 Dec 2015 Chad

Chad (view profile)

Could you tell me that your code is related to which paper?

15 Jan 2015 sara

sara (view profile)

04 Dec 2012 Nad

Nad (view profile)

05 Jan 2011 Brett Shoelson

Brett Shoelson (view profile)

The NEW version is now available; have at it! Comments/suggestions welcome.

Comment only
03 Jan 2011 Brett Shoelson

Brett Shoelson (view profile)

Please note: I've submitted a semi-major revision, and am waiting for it to clear. The function will soon accept as optional arguments all PV pairs accepted by BLOCKPROC, and a "fudge factor," by which to multiply the local value returned by graythresh. You may want to wait until the new version is up to download this.

Comment only
03 Jan 2011 1.2

Modified significantly to accept as optional inputs all parameter-value pairs accepted by BLOCKPROC, as well as an additional "fudge factor" parameter that allows one to scale the local graythresh value by a scalar multiple.

11 Jan 2011 1.3

Fixed problem with screenshot. (Image was inappropriately rotated.)

08 Feb 2011 1.4

Minor change to replace default blocksize of [32 32] by that returned by function BESTBLK.

01 Sep 2016

Updated license

Contact us