matlab拟合不显示直线,Matlab提取中心线后用hough拟合直线程序有问题,希望大家给指点一下...

具体程序如下

clc;

clear all;

close all;

I=imread('tu1.jpg');%由于图像本身为灰度图像,所以不需要灰度化

% I2=rgb2gray(I);

figure(1),imshow(I);

%%%%提取中心线start%%%%%%%%%%

a=I;

[max_a index]=max(a);              %找出a的格式

b=repmat(max_a,size(a,1),1);     %按矩阵a格式复制b矩阵,b矩阵全是最大值

a(a

figure(2),imshow(a);

%%%%%%%提取中心线end%%%%%%%%%%%%

%%%%%%%%%%%hough变换检测直线start%%%%%%%%%%%%

BW=a;

[H,T,R] = hough(BW,'RhoResolution',0.5,'ThetaResolution',0.5);

% display the original image显示原始图像

figure(3),imshow(imadjust(mat2gray(H)),'XData',T,'YData',R,'InitialMagnification','fit');

title('Hough transform of tu1.jpg ');

xlabel('\theta'), ylabel('\rho');

axis on, axis normal, hold on;

colormap(hot);

peaks = houghpeaks(H, 50,'threshold',ceil(0.3*max(H(:))));

lines = houghlines(BW, T, R,peaks);

figure(4),imshow(a);

lines(1).point2(1)=lines(1).point2(1)+315;

hold on

max_len = 0;

for k = 1:length(lines)

% 绘制各条线

xy = [lines(k).point1; lines(k).point2];

plot(xy(:,1),xy(:,2),'LineWidth',1,'Color','red');

end

hold off

%%%%%%%%%%%%%%hough变换检测直线end%%%%%%%%%%%%%%%%

45af122fe34f8660a9e3ee1f4f020af4.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值