计算机视觉实验5形态学滤波实验报告
(6页)
本资源提供全文预览,点击全文预览即可全文预览,如果喜欢文档就下载吧,查找使用更方便哦!
19.90 积分
Experiment 4:Thresholding ⅱ.You need to review Matlab programming language and M-file format.ⅲ. You should have studied image segmentation and mathematical morphology methods.ⅢⅢ. Experiment Contentsⅰ.Read “bac.bmp” file (to do this by imread function), convert the color image into grayscale image, and then perform thresholding by auto threshoding method using “while loop” and display the results in a Matlab window. 程序:%Iterative thresholdiclear all;im=imread('bac.bmp');subplot(1,2,1);imshow(im);title('Gray image');[Y X]=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('image after Auto_thresholding');ⅱ. Read “bw_bac.bmp” file and “bw_bac2.bmp”(to do this by imread function), perform mathematical morphology to fill the small holes in objects and display the results in a Matlab window.腐蚀:mask=[1 1 1;1 1 1;1 1 1];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));for kk=2:Y-1for k=2:X-1%Calculating sigmaimblock=im(k-1:k+1,kk-1:kk+1);sigma=sum(sum(imblockif sigma 0im_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, convert the color image into gray scale image, then perform thresholding I=imread('Plate.JPG'); im=rgb2gray(I);subplot(3,2,1);imshow(im); title('Gray image');[Y X]=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('image after Auto_thresholding');mask=[1 1 1;1 1 1;1 1 1];im_new=zeros(Y,X);T=sum(sum(mask));for kk=2:X-1for k=2:Y-1 imblock=im_bi(k-1:k+1,kk-1:kk+1);sigma=sum(sum(imblock if sigma 0im_new(i,j)=1;elseim_new(i,j)=new(i,j);endendendsubplot(3,2,4)imagesc(im_new);colormap(gray);title('image after open'); 关 键 词: 计算机 视觉 实验 形态学 滤波 报告
天天文库所有资源均是用户自行上传分享,仅供网友学习交流,未经上传用户书面授权,请勿作他用。