matlab图像分割程序

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

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

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

资源描述

Img=imread('t11.jpg');%ThesamecellimageinthepaperisusedhereImg=double(Img(:,:,1));sigma=1.5;%scaleparameterinGaussiankernelforsmoothing.G=fspecial('gaussian',15,sigma);Img_smooth=conv2(Img,G,'same');%smoothimagebyGaussiinconvolution[Ix,Iy]=gradient(Img_smooth);f=Ix.^2+Iy.^2;g=1./(1+f);%edgeindicatorfunction.epsilon=1.5;%thepapramaterinthedefinitionofsmoothedDiracfunctiontimestep=5;%timestep,trytimestep=10,20,...,50,...mu=0.2/timestep;%coefficientoftheinternal(penalizing)energytermP(\phi)%Note:theproducttimestep*mumustbelessthan0.25forstability!lambda=5;%coefficientoftheweightedlengthtermLg(\phi)alf=1.5;%coefficientoftheweightedareatermAg(\phi);%Note:Chooseapositive(negative)alfiftheinitialcontourisoutside(inside)theobject.[nrow,ncol]=size(Img);figure;imagesc(Img,[0,255]);colormap(gray);holdon;text(6,6,'Leftclicktogetpoints,rightclicktogetendpoint','FontSize',[12],'Color','r');%Clickmousetospecifyinitialcontour/regionBW=roipoly;%getaregionRinsideapolygon,BWisabinaryimagewith1and0insideoroutsidethepolygon;c0=4;%theconstantvalueusedtodefinebinarylevelsetfunction;initialLSF=c0*2*(0.5-BW);%initiallevelsetfunction:-c0insideR,c0outsideR;u=initialLSF;[c,h]=contour(u,[00],'r');u=initialLSF;figure;imagesc(Img,[0,255]);colormap(gray);holdon;[c,h]=contour(u,[00],'r');title('Initialcontour');%startlevelsetevolutionforn=1:300u=EVOLUTION(u,g,lambda,mu,alf,epsilon,timestep,1);ifmod(n,20)==0pause(0.001);imagesc(Img,[0,255]);colormap(gray);holdon;[c,h]=contour(u,[00],'r');iterNum=[num2str(n),'iterations'];title(iterNum);holdoff;endendclose('figure1')close('figure2')axes(handles.fgh);imagesc(Img,[0,255]);colormap(gray);holdon;[c,h]=contour(u,[00],'r');totalIterNum=[num2str(n),'iterations'];

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

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

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

×
保存成功