您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 项目/工程管理 > 计算机视觉实验5形态学滤波实验报告
Experiment4:Thresholding&mathematicalmorphology王影电子1203班学号:1210910322Ⅰ.AimTheaimofthislaboratorysessionistolearntodealwithimagedatabyMatlab.Bytheendofthissession,youshouldbeabletoperformimagepreprocessingofthresholdingandmathematicalmorphology.Ⅱ.KnowledgerequiredintheExperimentⅰ.YouaresupposedtohavelearnedthebasicskillsofusingMatlab;ⅱ.YouneedtoreviewMatlabprogramminglanguageandM-fileformat.ⅲ.Youshouldhavestudiedimagesegmentationandmathematicalmorphologymethods.Ⅲ.ExperimentContentsⅰ.Read“bac.bmp”file(todothisbyimreadfunction),convertthecolorimageintograyscaleimage,andthenperformthresholdingbyautothreshodingmethodusing“whileloop”anddisplaytheresultsinaMatlabwindow.程序:%Iterativethresholdiclearall;im=imread('bac.bmp');subplot(1,2,1);imshow(im);title('Grayimage');[YX]=size(im);S=sum(sum(im));S=S/(X*Y);D=0.1;T=0;im_bi=imS;while(abs(S-T)D)im1=double(im_bi).*double(im);im2=double(abs(1-im_bi)).*double(im);S1=sum(sum(im1))/sum(sum(im_bi));S2=sum(sum(im2))/sum(sum(abs(1-im_bi)));T=S;S=(S1+S2)/2;im_bi=imS;endsubplot(1,2,2);imshow(im_bi);title('imageafterAuto_thresholding');ⅱ.Read“bw_bac.bmp”fileand“bw_bac2.bmp”(todothisbyimreadfunction),performmathematicalmorphologytofillthesmallholesinobjectsanddisplaytheresultsinaMatlabwindow.腐蚀:mask=[111;111;111];im=imread('bw_bac.bmp');figure(1)subplot(1,2,1);imagesc(im);colormap(gray);[Y,X]=size(im);im_new=zeros(Y,X);T=sum(sum(mask));forkk=2:Y-1fork=2:X-1%Calculatingsigmaimblock=im(k-1:k+1,kk-1:kk+1);sigma=sum(sum(imblock&mask));ifsigmaT;im_new(k,kk)=0;elseim_new(k,kk)=im(k,kk);endendendsubplot(1,2,2)imagesc(im_new);colormap(gray);膨胀:clear;im=imread('bw_bac2.bmp');figure(1)subplot(1,2,1);imagesc(im);colormap(gray);[Y,X]=size(im);im_new=zeros(Y,X);N=5;mask=ones(N,N);fori=(N+1)/2:Y-(N-1)/2forj=(N+1)/2:X-(N-1)/2%Calculatingsigmaimblock=im(i-(N-1)/2:i+(N-1)/2,j-(N-1)/2:j+(N-1)/2);sigma=sum(sum(imblock&mask));ifsigma0im_new(i,j)=1;elseim_new(i,j)=im(i,j);endendendsubplot(1,2,2)imagesc(im_new);colormap(gray);iii.Read“Plate.jpg”file,convertthecolorimageintograyscaleimage,thenperformthresholding&mathematicalmorphologyoperation,displaytheresultsinMatlabwindow.程序:clear;I=imread('Plate.JPG');im=rgb2gray(I);subplot(3,2,1);imshow(im);title('Grayimage');[YX]=size(im);S=sum(sum(im));S=S/(X*Y);D=0.1;T=0;im_bi=imS;while(abs(S-T)D)im1=double(im_bi).*double(im);im2=double(abs(1-im_bi)).*double(im);S1=sum(sum(im1))/sum(sum(im_bi));S2=sum(sum(im2))/sum(sum(abs(1-im_bi)));T=S;S=(S1+S2)/2;im_bi=imS;endsubplot(3,2,2);imshow(im_bi);title('imageafterAuto_thresholding');mask=[111;111;111];im_new=zeros(Y,X);T=sum(sum(mask));forkk=2:X-1fork=2:Y-1imblock=im_bi(k-1:k+1,kk-1:kk+1);sigma=sum(sum(imblock&mask));ifsigmaT;new(k,kk)=0;elsenew(k,kk)=im_bi(k,kk);endendendsubplot(3,2,3);imshow(new);title('imageafterErosion');[A,B]=size(new);N=3;mask=ones(N,N);fori=(N+1)/2:A-(N-1)/2forj=(N+1)/2:B-(N-1)/2block=new(i-(N-1)/2:i+(N-1)/2,j-(N-1)/2:j+(N-1)/2);gma=sum(sum(block&mask));ifgma0im_new(i,j)=1;elseim_new(i,j)=new(i,j);endendendsubplot(3,2,4)imagesc(im_new);colormap(gray);title('imageafteropen');
本文标题:计算机视觉实验5形态学滤波实验报告
链接地址:https://www.777doc.com/doc-7255968 .html