Hough变换直线检测MatLab代码.docx

  1. 1、本文档共10页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
Hough变换直线检测MatLab代码

? Hough变换直线检测MatLab代码一.function Img_hough = hough_s(Img, bw)%该函数实现hough变换提取直线的功能。%输入图像x,运行之后直接画出直线。%选择进行Hough变换的图像行%Img为原图像;bw为边缘图像%%[H,W,D]=size(Img);Img_hough = Img;if D==1??? channel = Img_hough;??? Img_hough = cat(3,channel, channel, channel);end[M,N]=size(bw);%求出图像大小。%%dtheta=1;drho=1;md=ceil((N+round(sqrt(M^2+N^2)))/drho);%确定网格的最大区域。ma=ceil(180/dtheta);numrhotheta=zeros(md,ma);%产生计数矩阵。coordrhotheta=cell(1,1);% para=cell(1,3);?ll数组相当于c语言中的指针,可动态的改变大小。for i=1:md??? for j=1:ma??????? coordrhotheta{i,j}=[];??? endend%产生空网格。ymin = 5;ymax = M - 4;for i=ymin:ymax??? for j=1:N??????? if bw(i,j) == 1??????????? for k=1:ma??????????????? rho=round((j*cos(dtheta*k*pi/180)+i*sin(dtheta*k*pi/180))/drho);??????????????? %根据直线的法线式表示,计算出平面上不同点的hough变换值。??????????????? rho=rho+ceil(N/drho);%可能的最大负值。??????????????? numrhotheta(rho+1,k)=numrhotheta(rho+1,k)+1;??????????????? %将hough变换值相应位置的计数值加1。??????????????? coordrhotheta{rho+1,k}=[coordrhotheta{rho+1,k};[i,j]];??????????????? %记录hough变换值相应位置对应的点的坐标。??????????? end??????? end??? endend%%figure;imshow(Img);hold onnum = 8;for i=1 : num??? [y1,col1]=max(numrhotheta);??? [y2,col]=max(y1);??? row=col1(col);??? %求出hough变换值最大值的坐标。??? numrhotheta(row,col)=0;??? %为了避免重复计算,将计算过的点置0。??? rhood=1;??? chood=0;??? top=max(row-rhood,1);??? down=min(row+rhood,md);??? left=max(col-chood,1);??? right=min(col+chood,ma);??? numrhotheta(top:down,left:right)=0;??? %???? nds=coordrhotheta{row,col};??? nds = [];??? for r = top : down??????? for c = left : right??????????? nds = [nds; coordrhotheta{r, c}];??????? end??? end??? Img_hough=draw(Img_hough, nds);endimwrite(mat2gray(numrhotheta),numrhotheta.bmp) ??二.RGB = imread(gantrycrane.png); I = rgb2gray(RGB); % convert to intensity BW = edge(I,canny); % extract edges [H,T,R] = hough(BW,RhoResolution,0.5,ThetaResolution,0.5); % display the original image subplot(2,1,1); imshow(RGB); title(gantrycrane.png); % display the hough matrix subplot(2,1,2); imshow(imadjust(mat2gray(H)),XData,T,YData,R,... Initi

文档评论(0)

xcs88858 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

版权声明书
用户编号:8130065136000003

1亿VIP精品文档

相关文档