阈值分割法代码

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

clc;clear;I=imread('cameraman.tif');figure;imshow(I);title('原图像');I=double(I);[n,m]=size(I);%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%迭代法求阈值T=ones(100,1);T(2)=(min(I(:))+max(I(:)))/2;T(1)=0;t=2;whileabs(T(t)-T(t-1))1%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%a=0;A=0;b=0;B=0;fori=1:nforj=1:mifI(i,j)T(t)a=a+1;A=A+I(i,j);else%%循环的主体b=b+1;B=B+I(i,j);endendendu1=A/a;u2=B/b;t=t+1;T(t)=0.5*(u1+u2);%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%end%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%根据迭代法求得的阈值进行分割fori=1:nforj=1:mifI(i,j)T(t)I(i,j)=0;elseI(i,j)=1;endendend%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%显示处理图像figure;imshow(double(I));title('分割图像');

1 / 2
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功