資源描述:
《matlab車道線檢測》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在工程資料-天天文庫。
1、word完美格式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(
2、i,j)=A(i,j,3);%提取圖像的藍(lán)色分量endendfori=1:r;forj=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('彩色通道提取法-灰度圖');%%%%
3、%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%精心整理學(xué)習(xí)幫手word完美格式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);%%%%%%%%%%%%%%
4、%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%i=h1;%直方圖均衡化后的圖像j=imnoise(i,'salt&pepper',0.02)k1=medfilt2(j);figure;subplot(121);imshow(j);title('添加椒鹽噪聲圖像')subplot(122);imshow(k1);title('3*3模板中值濾波')%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%clcr2g
5、;figure;subplot(221);imshow(r2g);title('原圖像');W_H1=[230;%選用自定義差分模板增強(qiáng)左車道標(biāo)記線30-3;0-3-2];W_V1=[032;%選用自定義差分模板增強(qiáng)右車道標(biāo)記線-303;-2-30];T=0.28;%thethresholdinthe2-valueI=r2g;%readtheimage[height,width]=size(I);I1=double(I);I3=double(I);I4=double(I);I2=zeros(height
6、+2,width+2);%puttheimage'sdataintoa精心整理學(xué)習(xí)幫手word完美格式biggerarraytovoidtheedgeI2(2:height+1,2:width+1)=I1;fori=2:height+1%movethewindowandcalculatethegradsforj=2:width+1sum3=0;%不同方向的模板算子sum4=0;form=-1:1forn=-1:1sum3=sum3+W_H1(m+2,n+2)*I2(i+m,j+n);endendform
7、=-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)=1;%二值化elseI3(i,j)=0;en
8、dendendsubplot(222);精心整理學(xué)習(xí)幫手word完美格式imshow(I3);title('sl、sr算子處理的圖像')%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%figure;subplot(221);imshow(A);title('原圖')gg=bwmorph(I3,'thin',inf);subplot(222);imshow(gg);title('細(xì)化的圖像')I=r