⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ostu.m

📁 ostu图像分割阈值算法,对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 + -