精选优质文档-----倾情为你奉上
精选优质文档-----倾情为你奉上
专心---专注---专业
专心---专注---专业
精选优质文档-----倾情为你奉上
专心---专注---专业
计算机科学与通信工程学院
U及迭代法求阈值。结果如图2,3所示
I=imread('');
[width,height]=size(I);
%otsu algorithm
level=graythresh(I);
BW=im2bw(I,level);
figure
imshow(BW)
%global threshold
for i=1:width
for j=1:height
if(I(i,j) < 80)
BW1(i,j)=0;
else
精选优质文档-----倾情为你奉上
精选优质文档-----倾情为你奉上
专心---专注---专业
专心---专注---专业
精选优质文档-----倾情为你奉上
专心---专注---专业
BW1(i,j)=1;
end
end
end
figure
imshow(BW1)
%迭代求阈值
I=double(I);
T=(min(I(:))+max(I(:)))/2;
done=false;
i=0;
while ~done
r1=find(I<=T);
r2=find(I>T);
Tnew=(mean(I(r1))+mean(I(r2)))/2;
done=abs(Tnew -T)<1;
T=Tnew;
i=i+1;
end
I(r1)=0;
I(r2)=1;
Figure;
imshow(I)
用分水岭算法分割图像:
center1=-10;
center2=-center1;
dist=sqrt(2*(2*center1)^2);
radius=(dist/2) * ;
lims=[floor(center1-*radius) ceil(center2+*radius)];
[x,y]=meshgrid(lims(1):lims(2));
bw1=sqrt((x-center1).^2 + (y-center1).^2) <= radius;
bw2=sqrt((x-center2).^2 + (y-center2).^2) <= radius;
bw=bw1 | bw2;
figure, imshow(bw,'InitialMagnification','fit'), title('二进制图像')
D=bwdist(~bw);
figure, imshow(D,[],'InitialMagnification','fit')
title('距离变换')
D=-D;
D(~bw)=-Inf;
L=watershed(D);
rgb=label2rgb(L,'jet',[.5 .5 .5]);
figure, imshow(rgb,'InitialMagnification','
数字图像处理——阈值分割(共7页) 来自淘豆网m.daumloan.com转载请标明出处.