File Exchange

image thumbnail

Local Adaptive Thresholding

version 1.0 (144 KB) by

Threshold with local statistics, such as mean or median.

4.23077
26 Ratings

173 Downloads

Updated

View License

ADAPTIVETHRESHOLD An adaptive thresholding algorithm that seperates the foreground from the background with nonuniform illumination.
  bw=adaptivethreshold(IM,ws,C) outputs a binary image bw with the local threshold mean-C or median-C to the image IM.
ws is the local window size.

tm is 0 or 1, a switch between mean and median. tm=0 mean(default); tm=1 median.

Contributed by Guanglei Xiong (xgl99@mails.tsinghua.edu.cn) at Tsinghua University, Beijing, China.

For more information, please see
  http://homepages.inf.ed.ac.uk/rbf/HIPR2/adpthrsh.htm

Comments and Ratings (40)

Cheng Ning

nice and simple

Ely Raz

I compared Local Adaptive Thresholding from Matlab File Exchange ( https://www.mathworks.com/matlabcentral/fileexchange/8647-local-adaptive-thresholding ) vs. the adaptthresh function (Matlab built in function) and I get different outputs. Are these two functions similar and can be compered? The adpt1 is my desired output and can I achieve the same using adaptthresh?

Code:

I = imread('rice.png');

adpt1=adaptivethreshold(I,75,0.01,1);
val= adaptthresh(I, 0.01);
adpt2 = imbinarize(I,val);

imshowpair(adpt1, adpt2, 'montage');

sairam to all members
 if any one has the Adaptive Thresholding for Edge Detection in
Gray Scale Images code can please provid to me

So good do far

@Yasha Jain, for me, ignoring C and following @2one's suggestion (on 3rd July 2014) worked. You can try as well.

Aurik Sarker

Yasha Jain

How do we decide the value of C

What is that ws(wnidow size)??

Andraz Skoda

sanjay bhattacharya wrote:

''I have written a code without using any std functions like imfilter etc, its purely based on fundamentals.

CHECK OUT THE OUTPUT IMAGES
http://sites.google.com/site/adapthresh/''

sanjay bhattacharya, this is exactly what I need. Is there any chance to show me hot your code looks like? Offcourse anyone else can help.

tnx!

learn121

Thank you!

2one

2one (view profile)

For others, it appears that C (=constant) was originally the binary image segmentation threshold.

I have modified my version of the code as follows:

replace:

sIM=mIM-IM-C;
bw=im2bw(sIM,0);

with:

sIM=mIM-IM;
thresh=graythresh(sIM);
bw=im2bw(sIM,thresh);

This now uses the adaptive (mean) filter to highlight image features (i.e. mIM-IM) and then the Otsu threshold to segment and generate a binary image.

2one

2one (view profile)

this works quite well for my application but can anyone explain to me what the algorithm is doing exactly?
I understand that the algorithm generates a local mean filtered image by iterating over each pixel for user window size but what is line:

sIM=mIM-IM-C

this subtracts the original image and a constant, C, from the local mean filtered image. What is C and why do this?

Kang Zheng

What is C exactly?

Hokchhay Tann

Great code, but not applicable to my type of images. I'm trying to make the threshold automated since I have a hundred thousands of this kind. I appreciate any suggestions.

https://sites.google.com/site/hokchhay10/

Shashi

Shashi (view profile)

I did apply this algorithm on my images but it didn't work out completely. There is a research paper by Q.Huang et.al. which speaks about Otsu's thresholding using adaptive window. I would like to know if somebody has implemented that.

Rosidah Lazid

Had anyone here used this code for processing trabecular micro CT images? Appreciate your feedback on the outcome. Thanks.

eray

eray (view profile)

Very simple and effective, thanks!

Nek Valous

Great script!

Ana Triana

Easy to read and use. Thank you.

what is that window size?

Martin

Martin (view profile)

is it possible to detect laser traces on an object using this algorithm?

Hans Müller

@Sanjay

How about sharing it, then?

it can detect the letters even where its very dark (see the lines in the end) line 8 etc

I have written a code without using any std functions like imfilter etc, its purely based on fundamentals.

CHECK OUT THE OUTPUT IMAGES
http://sites.google.com/site/adapthresh/

Nice code, but not applicable in extreme situations.

hafid rafi

it's very very simple thanks

Guillermo Moreno

Simple and Fast, thanks

alev soke

thank you very much.
it is a perfect program.

zhang shi jie

really nice

ranjeeth dasineni

works great man!!

kayalvizhi lakshmanan

saravanan radhakrishnan

really good code

mel tem

thank you

amit vishnipolsky

saravanan kumar

nice work

Piyorot Khongchuay

cool

Alan Zhang

The 2 lines near the end should be changed from:
sIM=mIM-IM;
bw=im2bw(sIM,C);
to:
sIM=mIM-IM-C;
bw=im2bw(sIM,0);
This change allows C to be +ve and negative. In the old code bw=im2bw(sIM,C) causes error when C is -ve.

tester Mc tester

it didnt work!!
i get
Error using ==> mat2gray
A must be double

J. Zhou

Pretty cool results with flexible options.
Great job!

Updates

1.0

BSD

remove unnecessary Thumbs.db in zip file

MATLAB Release
MATLAB 7.0.4 (R14SP2)

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

» Watch video