?? ostu.m
字號:
function H_total=ostu(threshold)
% fxy=fstatus(xy);
% 適應值函數 xy為多維數組
% 對約束化問題,這里用懲罰函數的外點法,
% 懲罰函數法的基本思想是借助懲罰函數把約束化問題轉化為列約束化問題.
% 外點法 對違反約束的點在目標函數中加入相應的懲罰,而對可行點不懲罰.
% 求:max f(x,y)
global G_min G_max
fvarsize=size(threshold);
H_total=zeros(fvarsize(1),1);
global p
w1=0;%定義參數
w2=0;
u1=0;
u2=0;
u=0;
m=1;
%f1=csvread('d:\f1.txt');
%p=f1;
%for a=1:254
%s=f1(a)+s; %計算總的像素數
%end
%for a=1:254
% p(a)=f1(a)/s;
%end %計算各灰度值的概率
threshold(1)=round(threshold(1));
for m=G_min:threshold(1)
w1=p(m,1)+w1;%目標類的總概率
end
for m=threshold(1)+1:G_max
w2=p(m,1)+w2; %背景類的總概率
end
for m=G_min:threshold(1)
u1=m*p(m,1)+u1;%目標類的均值
end
u1=u1/w1;
for m=threshold(1)+1:G_max
u2=m*p(m,1)+u2;%背景類的均值
end
u2=u2/w2;
u=(u1*w1)+(u2*w2);
H_total=(w1*(u1-u)^2)+(w2*(u2-u)^2);
if(u2==0 )
fx=0;
end
if(u1==0)
fx=0;
end
end
%fx(1)y=-fx(1)y;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -