您好,欢迎访问三七文档
实验九图像边缘检测20124178付蕊一、实验目的及要求掌握图像边缘检测的主要原理和常用方法;依据边缘检测理论,实现灰度图像一阶和二阶边缘检测方法;了解利用小波变换进行图像边缘检测的原理;启发学生依据边缘特征进行图像分析与识别,提高学生图像处理与分析能力和实际动手能力。二、实验设备与软件1.PC计算机2.MATLAB软件/语言包括图像处理工具箱(ImageProcessingToolbox)3.实验所需要的图片4.移动式存储器(软盘、U盘等)三、实验内容1.编程实现一阶差分边缘检测算法,包括Robert梯度算子、Prewitt算子、Sobel算子等;2.编程实现二阶差分拉普拉斯边缘检测算法以及LoG检测法和Canny检测法;3.分析与比较各种边缘检测算法的性能;4.编程实现小波的边缘检测算法。六、实验步骤1.打开一幅灰度图像,利用MATLAB工具箱所提供的edge函数,用典型的几种边缘检测算子,分别对图像进行边缘检测,显示检测结果;I=imread('tire.tif');subplot(2,2,1);imshow(I);title('原图');[gv,t1]=edge(I,'sobel','vertical');subplot(2,2,2);imshow(gv);title('sobel垂直边缘');[gb,t2]=edge(I,'sobel','horizontal');subplot(2,2,3);imshow(gb);title('sobel垂直边缘');w45=[-2-10;-101;012];g45=imfilter(double(I),w45,'replicate');T=0.3*max(abs(g45(:)));g45=g45=T;subplot(2,2,4);imshow(g45);title('sobel45度方向边缘');2.分析比较不同算子的检测效果;I=imread('rice.bmp');BW1=edge(I,'sobel');%利用Sobel算子进行边缘检测BW2=edge(I,'roberts');%利用roberts算子进行边缘检测BW3=edge(I,'prewitt');%利用prewitt算子进行边缘检测BW4=edge(I,'log');%利用log算子进行边缘检测BW5=edge(I,'canny');%利用canny算子进行边缘检测subplot(2,3,1),imshow(I)title('原图');subplot(2,3,2),imshow(BW1)title('Sobel算子');subplot(2,3,3),imshow(BW2)title('roberts算子');subplot(2,3,4),imshow(BW3)title('prewitt算子');subplot(2,3,5),imshow(BW4)title('log算子');subplot(2,3,6),imshow(BW5)title('canny算子');3.利用小波变换对图像进行边缘检测,分析检测结果;X=imread('rice.bmp');subplot(1,2,1);imshow(X);title('原图像');clearcoef1;clearcoef2;clearcoef3;clearform;x=X;x=double(x);[line,column]=size(x);J=6;Tu=7;smooth_area_num=20;edge_area_num=40;fori=1:linecoef1(i,:)=cwt(x(i,:),1,'bior4.4');coef2(i,:)=cwt(x(i,:),2,'bior4.4');coef3(i,:)=cwt(x(i,:),J,'bior4.4');endmax=0;max_loc=0;max_num=10;form=zeros(line,column);fori=1:linej=1;whilejcolumn-1if(coef3(i,j)0&coef3(i,j+1)0)|(coef3(i,j)0&coef3(i,j+1)0)fork=j+1:column-1ifcoef3(i,k)*coef3(i,j)=0form=j:kifabs(coef3(i,m))maxmax=abs(coef3(i,m));max_loc=m;endendifmaxmax_numform(i,max_loc)=1;endj=k;max=0;break;endendifk==column-1j=column-1;endelsej=j+1;endendendx=x';fori=1:linecoef1(i,:)=cwt(x(i,:),1,'bior4.4');coef2(i,:)=cwt(x(i,:),2,'bior4.4');coef3(i,:)=cwt(x(i,:),J,'bior4.4');endmax=0;max_loc=0;fori=1:linej=1;whilejcolumn-1if(coef3(i,j)0&&coef3(i,j+1)0)||(coef3(i,j)0&&coef3(i,j+1)0)fork=j+1:column-1ifcoef3(i,k)*coef3(i,j)=0form=j:kifabs(coef3(i,m))maxmax=abs(coef3(i,m));max_loc=m;endendifmaxmax_numform(max_loc,i)=1;endj=k;max=0;break;endendifk==column-1j=column-1;endelsej=j+1;endendendfori=2:line-2forj=2:column-2ifform(i,j-1)==0&form(i,j+1)==0&form(i-1,j-1)==0&form(i-1,j)==0&form(i-1,j+1)==0&form(i+1,j-1)==0&form(i+1,j)==0&form(i+1,j+1)==0form(i,j)=0;end%0000%0110%0000ifform(i,j)==1&form(i,j+1)==1&sum(sum(form(i-1:i+1,j-1:j+2)))==2form(i,j)=0;form(i,j+1)=0;end%000%010%010%000ifform(i,j)==1&form(i+1,j)==1&sum(sum(form(i-1:i+2,j-1:j+1)))==2form(i,j)=0;form(i+1,j)=0;end%0000%0100%0010%0000ifform(i,j)==1&form(i+1,j+1)==1&sum(sum(form(i:i+1,j:j+1)))==2ifsum(sum(form(i-1:i+2,j-1:j+2)))==3&(form(i-1,j+2)==1|form(i+2,j-1)==1)form(i,j)=0;form(i+1,j+1)=0;endifsum(sum(form(i-1:i+2,j-1:j+2)))==4&form(i-1,j+2)==1&form(i+2,j-1)==1form(i,j)=0;form(i+1,j+1)=0;endend%0000%0010%0100%0000ifform(i,j+1)==1&form(i+1,j)==1&sum(sum(form(i:i+1,j:j+1)))==2ifsum(sum(form(i-1:i+2,j-1:j+2)))==3&(form(i-1,j-1)==1|form(i+2,j+2)==1)form(i,j+1)=0;form(i+1,j)=0;endifsum(sum(form(i-1:i+2,j-1:j+2)))==4&form(i-1,j-1)==1&form(i+2,j+2)==1form(i,j+1)=0;form(i+1,j)=0;endendendendmax=0;fori=3:line-3forj=3:column-3s=sum(sum(form(i-2:i+2,j-2:j+2)));form=i-2:i+2forn=j-2:j+2ifs=7&abs(coef3(m,n))=s*2form(m,n)=0;endendendendendsubplot(1,2,2);imshow(form);title('边缘图像');
本文标题:实验九图像边缘检测
链接地址:https://www.777doc.com/doc-2458479 .html