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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
close all;
clear all;
a=imread('1.jpg');
[m n]=size(a);
total1=zeros(1,254);
total2=zeros(1,254);
num1=zeros(1,254);
num2=zeros(1,254);
s=zeros(1,254);
for th=1:254
for i=1:m
for j=1:n
if(a(i,j)<th)
total1(1,th)=double(total1(1,th))+double(a(i,j));
num1(1,th)=num1(1,th)+1;
else
total2(1,th)=double(total2(1,th))+double(a(i,j));
num2(1,th)=num2(1,th)+1;
end
end
end
end
for i=1:254
if (num1(1,i)~=0&num2(1,i)~=0)
mean1(1,i)=total1(1,i)/num1(1,i);
mean2(1,i)=total2(1,i)/num2(1,i);
end
end
for i=1:254
if (num1(1,i)~=0&num2(1,i)~=0)
s(1,i)=(mean2(1,i)-double(i))*(double(i)-mean1(1,i))/(mean2(1,i)-mean1(1,i))/(mean2(1,i)-mean1(1,i));
end
end
for i=1:254
if(s(1,i)==max(s))
thresult=i;
end
end
for i=1:m
for j=1:n
if(a(i,j)<thresult)
b(i,j)=0;
else
b(i,j)=255;
end
end
end
figure,subplot(1,2,1),imshow(a),subplot(1,2,2),imshow(b,[]);
|