基于积分图的自适应阈值分割的matlab源代码

2012-04-07 11:50

paper title : Adaptive Thresholding using Integral Image

matlab code is listed as follow:

function outputbinaryimage = adaptivethresholding(inputimage)
if ndims(inputimage) == 3
inputimage = rgb2gray(inputimage);
end
inputimage = double(inputimage);
[width height] = size(inputimage);
outputbinaryimage = zeros(width,height);
s = width/8;
t = 15;
intimg = ones(width,height).*255;
for i = 1:width
sum = 0;
for j = 1:height
sum = sum + inputimage(i,j);
if i == 1
intimg(i,j) = sum;
else
intimg(i,j) = intimg(i-1,j) + sum;
end
end
end
for i = 1:width
for j = 1:height
x1 = round(i – s/2);
x2 = round(i + s/2);
y1 = round(j – s/2);
y2 = round(j + s/2);
if x1 width
x1 = width;
end
if x2 > width
x2 = width;
end
if y1 height
y2 = height;
end
if y1 > height
y1 = height;
end
count = (x2 – x1 + 1) * (y2 – y1 + 1);
sumv = intimg(x2,y2) – intimg(x2,y1) – intimg(x1,y2) + intimg(x1,y1);
if inputimage(i,j) * count <= (sumv * (100.0 – t)/100)
outputbinaryimage(i,j) = 0;
else
outputbinaryimage(i,j) = 255;
end
end
end

点击微信扫一扫

星期日 星期一 星期二 星期三 星期四 星期五 星期六
26
27
28
29
30
31
1
 
 
 
 
 
 
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1
2
3
4
5
6
 
 
 
 
 
 

最近留言

没有数据
扫描二维码访问
欢迎使用手机扫描二维码访问