基于MATLAB的图像分割技术
更新时间:2024-06-11 09:09:01 阅读量: 综合文库 文档下载
利用阀值法对图像进行分割: >> f=imread('peppers.png'); >> f=rgb2gray(f); >> f=im2double(f);
>> t=0.5*(min(f(:))+max(f(:))); >> done=false; >> while ~done g=f>=t;
tn=0.5*(mean(f(g))+mean(f(~g))); done=abs(t-tn)<0.1; t=tn; end;
>> display('Threshold(t)-Iterative'); Threshold(t)-Iterative >> t t =
0.4691
>> r=im2bw(f,t);
>> subplot(2,2,1);imshow(f); >> subplot(2,2,2);imshow(r);
>> xlabel('迭代法全局阀值分割'); >> th=graythresh(f); >> th th =
0.3961
>> s=im2bw(f,th);
>> subplot(2,2,3);imshow(s); >> xlabel('全局阀值Otsu分割'); >> se=strel('disk',10); >> ft=imtophat(f,se); >> thr=graythresh(ft); >> thr thr =
0.1098
>> lt=im2bw(ft,thr);
>> subplot(2,2,4);imshow(lt); >> xlabel('局部阀值分割');
用迭代法对图像进行分割: >> i=imread('eight.tif'); >> zmax=max(max(i)); >> zmin=min(min(i)); >> tk=(zmax+zmin)/2; >> bcal=1;
>> isize=size(i); >> while (bcal) ifg=0; ibg=0; fg=0; bg=0;
for j=1:isize(1) for k=1:isize(2) tmp=i(j,k); if(tmp>=tk) ifg=ifg+1;
fg=fg+double(tmp); else
ibg=ibg+1;
bg=bg+double(tmp); end;
end; end;
zo=fg/ifg; zb=bg/ibg;
tktmp=uint8((zo+zb)/2); if(tktmp==tk) bcal=0; else
tk=tktmp; end; end;
>> disp(strcat('迭代后阀值',num2str(tk))); 迭代后阀值165
>> newi=im2bw(i,double(tk)/255); >> subplot(1,2,1);imshow(i); >> subplot(1,2,2);imshow(newi); >> xlabel('迭代法');
用Otsu法进行阀值选择: >> i=imread('coins.png'); >> subplot(1,2,1);imshow(i);
>> bw=im2bw(i,graythresh(getimage)); >> subplot(1,2,2);imshow(bw);
使用分水岭算法对图像进行分割:
>> c1=-10; >> c2=-c1;
>> dist=sqrt(2*(2*c1)^2); >> rad=dist/2*1.4;
>> li=[floor(c1-1.2*rad) ceil(c2+1.2*rad)]; >> [x,y]=meshgrid(li(1):li(2));
>> bw1=sqrt((x-c1).^2+(y-c1).^2)<=rad; >> bw2=sqrt((x-c2).^2+(y-c2).^2)<=rad; >> bw=bw1|bw2;
>> subplot(1,3,1);imshow(bw); >> d=bwdist(~bw);
>> subplot(1,3,2);imshow(d,[]); >> d=-d;
>> d(~bw)=-Inf; >> l=watershed(d);
>> rgb=label2rgb(l,'jet',[.5 .5 .5]); >> subplot(1,3,3);imshow(rgb);
使用分水岭算法: >> c1=-10; >> c2=-c1;
>> dist=sqrt(3*(2*c1)^2); >> rad=dist/2*1.4;
>> li=[floor(c1-1.2*rad) ceil(c2+1.2*rad)]; >> [x,y,z]=meshgrid(li(1):li(2));
>> bw1=sqrt((x-c1).^2+(y-c1).^2+(z-c1).^2)<=rad; >> bw2=sqrt((x-c2).^2+(y-c2).^2+(z-c2).^2)<=rad; >> bw=bw1|bw2;
>> figure;isosurface(x,y,z,bw,0.5);axis equal; >> set(gcf,'color','w');
>> xlim(li);ylim(li);zlim(li);
>> view(3);camlight;lighting gouraud; >> d=bwdist(~bw);
>> figure;isosurface(x,y,z,d,rad/2);axis equal; >> set(gcf,'color','w');
>> xlim(li);ylim(li);zlim(li);
>> view(3);camlight;lighting gouraud;
>> d=-d;
>> d(~bw)=-Inf; >> l=watershed(d); >> figure;
>> isosurface(x,y,z,l==2,0.5); >> isosurface(x,y,z,l==3,0.5); >> axis equal;
>> set(gcf,'color','w');
>> xlim(li);ylim(li);zlim(li);
>> view(3);camlight;lighting gouraud;
使用Sobel进行边缘检测: >> i=imread('circuit.tif'); >> bw1=edge(i,'roberts'); >> subplot(1,2,1);imshow(i); >> subplot(1,2,2);imshow(bw1); >> clear;
>> image=imread('circuit.tif'); >> i0=edge(image,'sobel'); >> i1=edge(image,'sobel',0.06); >> i2=edge(image,'sobel',0.04); >> i3=edge(image,'sobel',0.02); >> subplot(2,3,1);imshow(image); >> subplot(2,3,2);imshow(i0); >> subplot(2,3,3);imshow(i1); >> subplot(2,3,4);imshow(i2); >> subplot(2,3,5);imshow(i3);
使用Prewitt算子进行边缘检测: >> i=imread('rice.png'); >> subplot(2,2,1);imshow(i); >> bw3=edge(i,'prewitt');
>> subplot(2,2,2);imshow(bw3); >> [bw3,th3]=edge(i,'prewitt');
>> bw3=edge(i,'prewitt',0.05,'horizontal'); >> subplot(2,2,3);imshow(bw3);
>> bw3=edge(i,'prewitt',0.05,'vertical'); >> subplot(2,2,4);imshow(bw3);
使用Log算子进行边缘检测: >> i=imread('circuit.tif'); >> [bw1,th]=edge(i,'log'); >> subplot(2,3,1);imshow(i); >> subplot(2,3,2);imshow(bw1); >> bw2=edge(i,'log',0.0056); >> subplot(2,3,3);imshow(bw2); >> h=fspecial('gaussian',5);
>> [bw3,th3]=edge(i,'zerocross',[],h); >> subplot(2,3,4);imshow(bw3); >> bw4=edge(i,'zerocross',0.025,h); >> subplot(2,3,5);imshow(bw4);
使用Canny算子进行边缘检测: >> i=imread('circuit.tif'); >> subplot(1,3,1);imshow(i); >> [bw,th]=edge(i,'canny'); >> subplot(1,3,2);imshow(bw);
>> [bw1,th1]=edge(i,'canny',[0.2,0.6]); >> subplot(1,3,3);imshow(bw1);
正在阅读:
基于MATLAB的图像分割技术06-11
创建文明单位封皮09-13
2.8 欧洲东部、北亚和俄罗斯08-11
小学生三句半台词大全02-20
藻类及治理方法 - 图文06-26
感谢挫折作文600字02-04
管线探挖方案 - 图文12-07
这样的人让我佩服作文600字07-11
常用字练习贴08-14
- 上九美容知情同意书
- 部队班务会流程与具体内容
- 会计毕业论文
- 最新2018年高考生物第二轮复习生物专题5生物的变异和进化 - 图文
- 国际分销合同
- 山东省市政园林安全生产教育考核 模拟练习题4套
- 黑群晖DIY打造日记(附eSATA、NFS、WOL等设置) - 图文
- 我的备考之路--胜利就在前方
- 数据库教案1
- II . 用Krusal算法(避圈法)求最小生成树
- 应急管理工作会议上的讲话
- 农业区域品牌建设
- 机房消防报警系统设计及气体灭火防护
- 广告学A第3次作业
- “信息大爆炸的今天,我们距真相越来越近还是越来越远”一辩稿
- 工程测量学实践教程
- 入党积极分子思想汇报科学发展观
- 计算机网络与应用(含答案)
- 温室大棚温湿度控制系统(开题报告)
- 质量管理、食品安全管理手册