嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元微信扫码支付:2 元
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
在大噪声下对轨道限界的提取
clc
clear
I0=imread('nice1.jpg');
figure
imshow(I0);
title('原图')
I1= rgb2gray(I0); %转灰度图
I1=I1*1.5;
figure
imshow(I1);
title('灰度图')
I2=filter2(fspecial('average',3),I1)/255;
figure
imshow(I2)
title('均值滤波图')
thresh = graythresh(I2);
I3=im2bw(I2,124/255); %对图像二值化
figure();
imshow(I3);
title('二值化图')
I4=medfilt2(I3,[3,3]);
figure
imshow(I4);
title('中值滤波图')
I5=bwareaopen(I4,2250);
figure
imshow(I5)
I6=imdilate(I5,strel('disk',2));
figure
imshow(I6)
BW=edge(I6,'roberts'); %roberts算子进行边缘检测
figure
imshow(BW);
title('边缘图')
[H,T,R] = hough(BW,'RhoResolution',0.4,'ThetaResolution',0.4);
figure
imshow(H,[],'XData',T,'YData',R,'InitialMagnification','fit');
xlabel('\theta'), ylabel('\rho');
title('霍夫空间图')
axis on
axis normal
hold on
P=houghpeaks(H,2,'threshold',ceil(0.3*max(H(:)))); %在图像的霍夫变换中查找峰值
x=T(P(:,2)); y = R(P(:,1));
plot(x,y,'s','color','white');
%Find lines and plot them
lines = houghlines(BW,T,R,P,'FillGap',255,'MinLength',40);
%FillGap是一个正实数,用来表示同一图像中两条线段的距离。当两条线的距离小于这个指定值时,houghlines函数就会将这两条线合并成一条线。
%MinLength是一个正实数,用来确定是否保存线条。如果线条的长度小于这个值,线条将会被擦除,否则就保存。
figure;
imshow(I0);
title('a')
hold on;
max_len = 0;
for k = 1:length(lines)
xy = [lines(k).point1; lines(k).point2];
plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');
% Plot beginnings and ends of lines
plot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','yellow');
plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','red');
% Determine the endpoints of the longest line segment
len = norm(lines(k).point1 - lines(k).point2);
if ( len > max_len)
max_len = len;
xy_long = xy;
end
end
% highlight the longest line segment
plot(xy_long(:,1),xy_long(:,2),'LineWidth',2,'Color','blue');