图像分割算法基础.docx
- 文档编号:11069033
- 上传时间:2023-02-24
- 格式:DOCX
- 页数:15
- 大小:243.08KB
图像分割算法基础.docx
《图像分割算法基础.docx》由会员分享,可在线阅读,更多相关《图像分割算法基础.docx(15页珍藏版)》请在冰豆网上搜索。
图像分割算法基础
实验四图像分割算法基础
一、实验目的
掌握基本的图象分割方法,观察图象分割的效果;加深对边缘检测、模板匹配、区域生长的理解;掌握一定的改善分割效果的技巧,如断裂边缘的连接(Hough变换)、加入图像特征描述子避免过分割现象(形态学分水岭分割算法)等;了解医学图像处理相对于其他图像处理的特点。
二、实验内容
1.点、线、边沿等灰度不连续性部位的检测;
2.房屋整体轮廓的检测与描绘;
3.Hough变换;
三、知识要点与范例
单色(灰度)图像的分割通常是基于图像强度的两个基本特征:
灰阶值的不连续性和灰度区域的相似性。
第一类方法主要是基于图像灰阶值的突然变换(如边缘)来分割图像,而第二类方法主要是把图像的某个子区域与某预定义的标准进行比较,以二者之间的相似性指标为指导来划分图像区域:
如阈值化技术、面向区域的方法、形态学分水岭分割算法等。
1.点检测
原理:
常数灰阶区域中的某孤立点对某种模板的响应绝对值肯定是最强烈的。
最常用的模板有:
Matlab实现方法:
g=abs(imfilter(double(f),w))>=T;wherewisaappropriatepointdetectionmaskwhichsatisfiestheabovecondition.
实例:
thedetectionofisolatedbrightpointinthedarkgrayareaofthenortheastquadrant.
(imagesize:
675*675)
实例代码:
f=imread('Fig1002(a)(test_pattern_with_single_pixel).tif');
w=[-1-1-1;-18-1;-1-1-1];
g=abs(imfilter(double(f),w));
T=max(g(:
));
g=g>=T;
subplot(121);imshow(f);
title('theoriginalimage');
subplot(122);imshow(g(1:
end-400,400:
end));
title('theisolatedpointdetected(onlyapartdisplayed)');
======================================================================
2.线(通常假定一个象素厚度)检测
原理与上同,典型模板有(主要方向性):
实例:
-450方向线的检测:
3.边沿检测
方法:
使用一阶或者二阶导数。
对一节导数,关键问题是怎样估计水平和垂直方向的梯度Gx和Gy,二阶导数通常使用Laplacian算子计算,但是Laplacian算子很少单独用来检测边缘,因为其对噪声非常敏感,而且其结果会产生双边沿,加大了边缘检测的困难。
然而,如果Laplacian算子能与其他边缘检测算法相结合,如边缘定位算法,则其是一个强有力的补充。
通常两个标准用来测度图像强度的迅速变化:
(1)找出强度的一阶导数值大于某个事先阈值标准的位置;
(2)找出图像二阶导数的跨零点。
IPT工具箱函数edge提供了几种基于上面两种标准的估计器:
其语法为:
[g,t]=edge(f,‘method’,parameters);
这里‘method’参数包括这几种类型的边缘检测子:
Sobel,Prewitt,Roberts,LaplacianofaGaussian(LoG),ZerocrossingsandCanny,前三种的模板见下图:
另一个强有力的边缘检测器:
CannyEdgeDetector(Canny[1986]),其算法的基本步骤如下:
(1)First,theimageissmoothedusingaGaussianfilterwithaspecifiedstandarddeviation
(2)Thelocalgradient,g(x,y)=[Gx2+Gy2]1/2,andedgedirection,(x,y)=tan-1(Gy/Gx),arecomputedateachpoint.AnyofthefirstthreetechniquescanbeusedtocomputertheGxandGy.Anedgepointisdefinedtobeapointwhosestrengthislocallymaximuminthedirectionofthegradient.
(3)Theedgepointsgiverisetoridgesinthegradientmagnitudeimage.Thealgorithmthentracksalongthetopoftheseridgesandsetstozeroallpixelsthatarenotactuallyontheridgetopsoastogiveathinline,aprocessknownasnonmaximalsuppression.Theridgepixelsarethethresholdedusingthresholds,T1andT2,withT1 (4)Finally,thealgorithmperformsedgelinkingbyincorporatingtheweakpixelsthatare8-connectedtostrongpixels. 注意: Edgefunctiondoesnotcomputeedgesat±450.Tocomputeedgesweneedtospecifythemaskanduseimfilter. 4.Hough变换 Inpractice,theresultingpixelsproducedbythemethodsdiscussedintheprevioussectionsseldomcharacterizeanedgecompletelybecauseofnoise,breaksfromnonuniformillumination,andothereffectsthatintroducespuriousdiscontinuities.HoughTransformisonetypeoflinkingproceduretofindandlinklinesegmentsforassemblingedgepixelsintomeaningfuledges. AbouttheprincipleofHoughtransform,pleaserefertopage586intextbook. InstanceofHoughtransform: %constructinganimagecontaining5isolatedforegroundpixelsinseverallocaitons: f=zeros(101,101); f(1,1)=1,f(101,1)=1,f(1,101)=1,f(101,101)=1,f(51,51)=1; [H,theta,rho]=hough(f);%houghtransform imshow(theta,rho,H,[],'notruesize'); axison,axisnormal; xlabel('\theta'),ylabel('\rho'); 四、参考程序和参考结果 1.房屋轮廓描绘 代码: f=imread('Fig1006(a)(building).tif'); [gv,t]=edge(f,'sobel','vertical'); subplot(231);imshow(f,[]); title('theoriginalimage'); subplot(232);imshow(gv,[]); title('verticaledgewiththresholddeterminedautomatically'); gv1=edge(f,'sobel',0.15,'vertical');%usingaspecifiedthreshold. subplot(233);imshow(gv1,[]); title('verticaledgewithaspecifiedthreshold'); gboth=edge(f,'sobel',0.15);%edgedetectionoftwodirections subplot(234);imshow(gboth,[]); title('horizontalandverticaledge'); %edgedetectionof450directionusingimfilterfunction w45=[-2-10;-101;012]; g45=imfilter(double(f),w45,'replicate'); T=0.3*max(abs(g45(: ))); g45=g45>=T; subplot(235);imshow(g45,[]); title('edgeat45withimfilter'); wm45=[012;-101;-2-10]; g45=imfilter(double(f),wm45,'replicate'); T=0.3*max(abs(g45(: ))); g45=g45>=T; subplot(236);imshow(g45,[]); title('edgeat-45withimfilter'); 另一个实验: 为比较三种检测方法的相对性能: Sobel,LoG和Cannyedgedetectors,和为了改善检测效果所需使用的技巧。 %usingthedefaultthreshold f=imread('Fig1006(a)(building).tif'); [gs_default,ts]=edge(f,'sobel'); [gl_default,tl]=edge(f,'log');andthedef [gc_default,tc]=edge(f,'canny');%tc=[90.047] %usingtheoptimalthresholdacquiredbymanualtest gs_best=edge(f,'sobel',0.05); gl_best=edge(f,'log',0.003,2.25); gc_best=edge(f,'canny',[0.040.1],1.5); Theleftcolumninabovefigureshowstheedgeimagesobtainedusingthedefaultsyntaxforthe‘sobel’,‘log’and‘canny’operatorrespectively,whereastherightcolumnaretheresultsusingoptimalthresholdandsigmavaluesobtainedbytry. 2.Hough变换用于线检测从而增强边缘的连续性 2.1Houghtransformforpeakdetection PeakdetectionisthefirststepinusingHoughtransformforlinedetectionandlinking.However,findingameaningfulsetofdistinctpeaksinaHoughtransformcanbechallenging.BecauseofthequantizationinspaceofthedigitalimageandinparameterspaceoftheHoughtransform,aswellasthefactthatedgesintypicalimagesarenotperfectlystraight,HoughtransformpeakstendtolieinmorethanoneHoughtransformcell.Onestrategytoovercomethisproblemisfollowing: (1)findtheHTcellcontainingthehighestvalueandrecorditslocation; (2)suppress(settozero)HTcellsintheimmediateneighborhoodofthemaximum; (3)repeatuntilthedesirednumberofpeakshasbeenfound,oruntilaspecifiedthresholdhasbeenreached. function[r,c,hnew]=houghpeaks(h,numpeaks,threshold,nhood) %HOUGHPEAKSDetectpeaksinHoughtransform. %[R,C,HNEW]=HOUGHPEAKS(H,NUMPEAKS,THRESHOLD,NHOOD)detects %peaksintheHoughtransformmatrixH.NUMPEAKSspecifiesthe %maximumnumberofpeaklocationstolookfor.ValuesofHbelow %THRESHOLDwillnotbeconsideredtobepeaks.NHOODisa %two-elementvectorspecifyingthesizeofthesuppression %neighborhood.Thisistheneighborhoodaroundeachpeakthatis %settozeroafterthepeakisidentified.TheelementsofNHOOD %mustbepositive,oddintegers.RandCaretherowandcolumn %coordinatesoftheidentifiedpeaks.HNEWistheHoughtransform %withpeakneighborhoodsuppressed. % %IfNHOODisomitted,itdefaultstothesmallestoddvalues>= %size(H)/50.IfTHRESHOLDisomitted,itdefaultsto %0.5*max(H(: )).IfNUMPEAKSisomitted,itdefaultsto1. ====================================================================== 2.2HTforlinedetectionandlinking Foreachpeak,thefirststepistofindthelocationofallnonzeropixelsintheimagethatcontributedtothatpeak.Thispurposecanbeimplementedbythefollowingfunction: function[r,c]=houghpixels(f,theta,rho,rbin,cbin) %HOUGHPIXELSComputeimagepixelsbelongingtoHoughtransformbin. %[R,C]=HOUGHPIXELS(F,THETA,RHO,RBIN,CBIN)computesthe %row-columnindices(R,C)fornonzeropixelsinimageFthatmap %toaparticularHoughtransformbin,(RBIN,CBIN).RBINandCBIN %arescalarsindicatingtherow-columnbinlocationintheHough %transformmatrixreturnedbyfunctionHOUGH.THETAandRHOare %thesecondandthirdoutputargumentsfromtheHOUGHfunction. [x,y,val]=find(f); x=x-1;y=y-1; theta_c=theta(cbin)*pi/180; rho_xy=x*cos(theta_c)+y*sin(theta_c); nrho=length(rho); slope=(nrho-1)/(rho(end)-rho (1)); rho_bin_index=round(slope*(rho_xy-rho (1))+1); idx=find(rho_bin_index==rbin); r=x(idx)+1;c=y(idx)+1; Thepixelsassociatedwiththelocationsfoundusinghoughpixlesmustbegroupedintolinesegments,whichisprogrammedintothefollowingfunction: functionlines=houghlines(f,theta,rho,rr,cc,fillgap,minlength) %HOUGHLINESExtractlinesegmentsbasedontheHoughtransform. %LINES=HOUGHLINES(F,THETA,RHO,RR,CC,FILLGAP,MINLENGTH) %extractslinesegmentsintheimageFassociatedwithparticular %binsinaHoughtransform.THETAandRHOarevectorsreturnedby %functionHOUGH.VectorsRRandCCspecifytherowsandcolumns %oftheHoughtransformbinstouseinsearchingforline %segments.IfHOUGHLINESfindstwolinesegmentsassociatedwith %thesameHoughtransformbinthatareseparatedbylessthan %FILLGAPpixels,HOUGHLINESmergesthemintoasingleline %segment.FILLGAPdefaultsto20ifomitted.Mergedline %segmentslessthanMINLENGTHpixelslongarediscarded. %MINLENGTHdefaultsto40ifomitted. %LINESisastructurearraywhoselengthequalsthenumberof %mergedlinesegmentsfound.Eachelementofthestructurearray %hasthesefields: % %point1End-pointofthelinesegment;two-elementvector %point2End-pointofthelinesegment;two-elementvector %lengthDistancebetweenpoint1andpoint2 %thetaAngle(indegrees)oftheHoughtransformbin %rhoRho-axispositionoftheHoughtransformbin 实例: %firstcomputeanddisplaytheHoughtransformusingafinerspacingthanthedefault. f=imread('Fig1006(a)(building).tif'); gc_best=edge(f,'canny',[0.040.1],1.5); [H,theta,rho]=hough(gc_best,0.5); imshow(theta,rho,H,[],'notruesize'); axison,axisnormal; xlabel('\theta'),ylabel('\rho') %nextusefunctionhoughpeakstofindfiveHTpeaks
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 图像 分割 算法 基础
![提示](https://static.bdocx.com/images/bang_tan.gif)