otsu算法的matlab程序,哪位能帮我注释一下,前面的我自己注释的,后面的有点看不懂。谢谢! 10
functionthreshold=otsu(filename);x=imread('E:\1.jpg');%读入图像[m,n]=size(x);%图像大小N=m*n;%...
function threshold=otsu(filename);
x=imread('E:\1.jpg');%读入图像
[m,n]=size(x);%图像大小
N=m*n;%像素个数
num=zeros(1,256);
p=zeros(1,256);%开辟0数组
for i=1:m
for j=1:n
num(x(i,j)+1)=num(x(i,j)+1)+1;%像素个数存入数组num中
end
end
for i=0:255;
p(i+1)=num(i+1)/N;%灰度值为i的概率,存入数组p中
end
totalmean=0;
for i=0:255;
totalmean=totalmean+i*p(i+1);%总平均灰度值
end
maxvar=0;%最大方差赋初值0
for k=0:255
kk=k+1;
zerosth=sum(p(1:kk));
firsth=0;
for h=0:k
firsth=firsth+h*p(h+1);
end
var=totalmean*zerosth-firsth;
var=var*var;
var=var/(zerosth*(1-zerosth)+0.01);
var=sqrt(var);
if(var>maxvar)
maxvar=var;
point=k;
end
end
threshold=point; 展开
x=imread('E:\1.jpg');%读入图像
[m,n]=size(x);%图像大小
N=m*n;%像素个数
num=zeros(1,256);
p=zeros(1,256);%开辟0数组
for i=1:m
for j=1:n
num(x(i,j)+1)=num(x(i,j)+1)+1;%像素个数存入数组num中
end
end
for i=0:255;
p(i+1)=num(i+1)/N;%灰度值为i的概率,存入数组p中
end
totalmean=0;
for i=0:255;
totalmean=totalmean+i*p(i+1);%总平均灰度值
end
maxvar=0;%最大方差赋初值0
for k=0:255
kk=k+1;
zerosth=sum(p(1:kk));
firsth=0;
for h=0:k
firsth=firsth+h*p(h+1);
end
var=totalmean*zerosth-firsth;
var=var*var;
var=var/(zerosth*(1-zerosth)+0.01);
var=sqrt(var);
if(var>maxvar)
maxvar=var;
point=k;
end
end
threshold=point; 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询