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);
Brett Shoelson (2020). ThresholdLocally (https://www.mathworks.com/matlabcentral/fileexchange/29764-thresholdlocally), MATLAB Central File Exchange. Retrieved .
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.
Could you tell me that your code is related to which paper?
The NEW version is now available; have at it! Comments/suggestions welcome.
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.
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!