急,求matlab的图像分割程序!!!
是基于最大类间方差法的,又称ostu算法,通过这个算法找到最佳阈值,然后将图像中灰度值大于和小于这个最佳阈值的分成两个图像,邮箱455299663@qq.com。...
是基于最大类间方差法的,又称ostu算法,通过这个算法找到最佳阈值,然后将图像中灰度值大于和小于这个最佳阈值的分成两个图像,邮箱455299663@qq.com。
展开
1个回答
展开全部
OSTU算法程序设计:
x=imread('G: ha.jpg');
%figure;
%imshow(x);
[m,n]=size(x);
N=m*n;
num=zeros(1,256);
p=zeros(1,256);
for i=1:m
for j=1:n
num(x(i,j)+1)=num(x(i,j)+1)+1;
end
end
for i=0:255;
p(i+1)=num(i+1)/N;
end
totalmean=0;
for i=0:255;
totalmean=totalmean+i*p(i+1);
end
maxvar=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;
for i=1:m
for j=1:n
if x(i,j)>point
bin(i,j)=1;
else
bin(i,j)=0;
end
end
end
imshow(bin);
x=imread('G: ha.jpg');
%figure;
%imshow(x);
[m,n]=size(x);
N=m*n;
num=zeros(1,256);
p=zeros(1,256);
for i=1:m
for j=1:n
num(x(i,j)+1)=num(x(i,j)+1)+1;
end
end
for i=0:255;
p(i+1)=num(i+1)/N;
end
totalmean=0;
for i=0:255;
totalmean=totalmean+i*p(i+1);
end
maxvar=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;
for i=1:m
for j=1:n
if x(i,j)>point
bin(i,j)=1;
else
bin(i,j)=0;
end
end
end
imshow(bin);
追问
我用你的程序做了下,细节不是很明显,图片分割后分成大块的黑色和白色,分割后的是这样
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询