收藏 分享(赏)

matlab 车道线检测.doc

上传人:HR专家 文档编号:7573576 上传时间:2019-05-21 格式:DOC 页数:8 大小:45KB
下载 相关 举报
matlab 车道线检测.doc_第1页
第1页 / 共8页
matlab 车道线检测.doc_第2页
第2页 / 共8页
matlab 车道线检测.doc_第3页
第3页 / 共8页
matlab 车道线检测.doc_第4页
第4页 / 共8页
matlab 车道线检测.doc_第5页
第5页 / 共8页
点击查看更多>>
资源描述

1、clc%读图最后得到灰度图像rgA=imread(999.png);r c d=size(A);r2g=zeros(r,c);red=zeros(r,c);green=zeros(r,c);blue=zeros(r,c);rg=zeros(r,c);for i=1:r;for j=1:c;red(i,j)=A(i,j,1);%提取图像的红色分量 green(i,j)=A(i,j,2);%提取图像的绿色分量blue(i,j)=A(i,j,3);%提取图像的蓝色分量endendfor i=1:r;for j=1:c;rg(i,j)=0.5*red(i,j)+0.5*green(i,j);enden

2、drg=uint8(rg);for i=1:r;for j=1:c;if rg(i,j)178;rg(i,j)=255;endendendfigure;subplot(2,2,1);imshow(A);title(原图)% 显示原图像subplot(222);imshow(rg);title(彩色通道提取法-灰度图);%figurer2g=rg;i=r2g;%输入灰度变换后的图像subplot(221);imshow(i);title(原图)subplot(223);imhist(i);%显示直方图h1=histeq(i);subplot(222);imshow(h1);title(直方图均衡

3、化后的图 )subplot(224);imhist(h1);%i=h1;%直方图均衡化后的图像j=imnoise(i,salt figure;subplot(121);imshow(j);title(添加椒盐噪声图像)subplot(122);imshow(k1);title(3*3模板中值滤波)%clcr2g;figure;subplot(221);imshow(r2g);title(原图像);W_H1=2 3 0;%选用自定义差分模板增强左车道标记线3 0 -3;0 -3 -2; W_V1= 0 3 2;%选用自定义差分模板增强右车道标记线-3 0 3;-2 -3 0;T = 0.28;

4、% the threshold in the 2-valueI = r2g; % read the imageheight,width = size(I);I1 = double(I);I3 = double(I);I4 = double(I);I2 = zeros(height+2,width+2); % put the images data into a bigger array to void the edgeI2(2:height+1,2:width+1) = I1;for i=2:height+1 % move the window and calculate the gradsf

5、or j=2:width+1sum3 = 0; % 不同方向的模板算子sum4 = 0;for m=-1:1for n=-1:1sum3= sum3 + W_H1(m + 2,n + 2) * I2(i + m,j + n);endendfor m=-1:1for n=-1:1 sum4 = sum4 + W_V1(m + 2,n + 2) * I2(i + m,j + n);endend grey1 = abs(sum3) + abs(sum4); I3(i-1,j-1) = grey1;endendbig = max(max(I3); % 归一化small = min(min(I3);fo

6、r i=1:heightfor j=1:widthI3(i,j) = (I3(i,j)-small)/(big - small); % 归一化if(I3(i,j) T)I3(i,j) = 1; % 二值化elseI3(i,j) = 0;endendend subplot(222);imshow(I3);title(sl、sr算子处理的图像 )%figure;subplot(221);imshow(A);title(原图)gg=bwmorph(I3,thin,inf);subplot(222);imshow(gg);title(细化的图像)I = rg;x,y=size(I);height,wi

7、dth = size(I);seedx=round(x);seedy=round(y/2);gr=I(seedx,seedy)W_H = 1 1 1; % the model in the horizon direction1 1 1;1 1 1;I1 = double(I);I2 = zeros(height+2,width+2); % put the images data into a bigger array to void the edgeI2(2:height+1,2:width+1) = I1;for i=2:height+1 % move the window and calc

8、ulate the gradsfor j=2:width+1sum1 = 0; % the cumulus for m=-1:1for n=-1:1sum1 = sum1 + W_H(m + 2,n + 2) * I2(i + m,j + n);endendgrey=sum1/9;I1(i-1,j-1) = grey;endendI1=uint8(I1);%邻域平均化灰度图像%subplot(222);imshow(I1);title(区域生长- 路面区域图像 )x,y=size(I1);I2=zeros(x,y);I=double(I);I1=double(I1);for i=1:x;for

9、 j=1:y;if abs(I1(i,j)-I(i,j)=70endendendsubplot(223)imshow(I2);title(区域生长-路面区域图像)I4=zeros(x,y);for i=round(5):x-4;for j=5:y-4;if gg(i,j)=1for m=i-4:i+4;for n=j-4:j+4;if I2(m,n)=0endendendendendendsubplot(224)imshow(I4);title(检测图像)%clc;t0=clockff=I4;%输入检测的图像x,y=size(ff);a1=zeros(x,1);b1=zeros(y,1);k=

10、1;for i=1:xfor j=1:round(y/2);if ff(i,j)=1;a1(k)=i;b1(k)=j;k=k+1;endendendm=length(a1);a2=max(a1)h=1;for i=1:m;if a1(i)=a2;jiaobiao(h)=i;h=h+1;endendb1=b1(jiaobiao);b11=max(b1);%ff(a1,b1)为选中的车道线第一个像素点k=1;for i=round(1):round(x);for j=1:round(y/2 );if ff(i,j)=1kkb(k)=(b11-j)/(a2-i);bbc(k)=b11-kkb(k)*

11、a2;k=k+1;endendend theta=atan(-1./kkb);theta1= theta+pi,roi=bbc.*sin(theta);roi1= roi+abs(roi);maxtheta=max( theta1);maxroi=max(roi1);accum=zeros(round(maxtheta)+1,round( maxroi)+1);for i=1:length(theta);thetaint=round( maxtheta/2+theta1(i)/2);roiint=round( maxroi/2+roi1(i)/2)+1;accum(thetaint,roiin

12、t)=accum( thetaint,roiint)+1;end p=max(max(accum)%出现峰值处的累加器的值for i=1:length(theta);thetaint=round( maxtheta/2+theta1(i)/2);roiint=round( maxroi/2+roi1(i)/2)+1;if accum(thetaint,roiint)=p;ji=i;endend k=1;m=1;for i=round(x/2):x;for j=1:round(y/2);if ff(i,j)=1kk(k)=(b11-j)/(a2-i);bb(k)=b11-kk(k)*a2;theta(k)=atan(-1./kk(k);if theta(k) =theta(ji) ;xji(m)=i;yji(m)=j;m=m+1;endk=k+1;endendend %xji=median(xji);%yji=median(yji);ji;theta(ji);imshow(I4);hold on;line( yji,b11 ,xji,a2,linewidth,3);title(根据改进的hough做标记线 )time = etime(clock, t0)

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 企业管理 > 管理学资料

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报