资源描述:
《matlab 车道线检测说课材料.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、精品好文档,推荐学习交流clc%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%读图最后得到灰度图像rgA=imread('999.png');[rcd]=size(A);r2g=zeros(r,c);red=zeros(r,c);green=zeros(r,c);blue=zeros(r,c);rg=zeros(r,c);fori=1:r;forj=1:c;red(i,j)=A(i,j,1);%提取图像的红色分量green(i,j)=A(i,j,2);%提取图像的绿色分量blue(i,j)=A(i,j,3);%提取图像的蓝色分量endendfori=1:r;fo
2、rj=1:c;rg(i,j)=0.5*red(i,j)+0.5*green(i,j);endendrg=uint8(rg);fori=1:r;forj=1:c;ifrg(i,j)>178;rg(i,j)=255;endendendfigure;subplot(2,2,1);imshow(A);title('原图')%显示原图像subplot(222);imshow(rg);title('彩色通道提取法-灰度图');仅供学习与交流,如有侵权请联系网站删除谢谢9精品好文档,推荐学习交流%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3、figurer2g=rg;i=r2g;%输入灰度变换后的图像subplot(221);imshow(i);title('原图')subplot(223);imhist(i);%显示直方图h1=histeq(i);subplot(222);imshow(h1);title('直方图均衡化后的图')subplot(224);imhist(h1);%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%i=h1;%直方图均衡化后的图像j=imnoise(i,'salt&pepper',0.02)k1=medfilt2(j);figure;subp
4、lot(121);imshow(j);title('添加椒盐噪声图像')subplot(122);imshow(k1);title('3*3模板中值滤波')%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%clcr2g;figure;subplot(221);imshow(r2g);title('原图像');W_H1=[230;%选用自定义差分模板增强左车道标记线30-3;0-3-2];W_V1=[032;%选用自定义差分模板增强右车道标记线-303;-2-30];T=0.28;%thethresholdinthe2-value
5、I=r2g;%readtheimage[height,width]=size(I);仅供学习与交流,如有侵权请联系网站删除谢谢9精品好文档,推荐学习交流I1=double(I);I3=double(I);I4=double(I);I2=zeros(height+2,width+2);%puttheimage'sdataintoabiggerarraytovoidtheedgeI2(2:height+1,2:width+1)=I1;fori=2:height+1%movethewindowandcalculatethegradsforj=2:width+1sum3=0;%不同方向的模板算子su
6、m4=0;form=-1:1forn=-1:1sum3=sum3+W_H1(m+2,n+2)*I2(i+m,j+n);endendform=-1:1forn=-1:1sum4=sum4+W_V1(m+2,n+2)*I2(i+m,j+n);endendgrey1=abs(sum3)+abs(sum4);I3(i-1,j-1)=grey1;endendbig=max(max(I3));%归一化small=min(min(I3));fori=1:heightforj=1:widthI3(i,j)=(I3(i,j)-small)/(big-small);%归一化if(I3(i,j)>T)I3(i,j
7、)=1;%二值化elseI3(i,j)=0;end仅供学习与交流,如有侵权请联系网站删除谢谢9精品好文档,推荐学习交流endendsubplot(222);imshow(I3);title('sl、sr算子处理的图像')%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%figure;subplot(221);imshow(A);title('原图')gg=bwmorp