-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLocalBinarization.m
64 lines (53 loc) · 1 KB
/
LocalBinarization.m
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
close all;
clc;
clear;
img=imread('katalog.bmp');
[X, Y]=size(img);
img_bin=img;
figure(1);
imshow(img);
win_size=30;
for x=1:X
for y=1:Y
treshold=meanLT(x,y,win_size,img,X,Y);
if(img(x,y)>treshold)
img_bin(x,y)=1;
else
img_bin(x,y)=0;
end
end
end
figure(2);
subplot(1,2,1);
imshow(img);
title("Orginal");
subplot(1,2,2);
imshow(boolean(img_bin));
title("Local Binzarization");
%%
window_size_2=30;
img_bin_2=img;
k=0.15;
R=128;
for x=1:X
for y=1:Y
mean=meanLT(x,y,window_size_2,img,X,Y);
deviation=stddevLT(x,y,window_size_2,img,mean,X,Y);
treshold=mean*(1+k*(deviation/R-1));
if(img(x,y)>treshold)
img_bin_2(x,y)=1;
else
img_bin_2(x,y)=0;
end
end
end
figure(3);
subplot(1,3,1);
imshow(img);
title("Orginal");
subplot(1,3,2);
imshow(boolean(img_bin));
title("Local Binzarization");
subplot(1,3,3);
imshow(boolean(img_bin));
title("Sauvol");