matlab虚拟环境 找到迷宫的最短路径源码程序 - matlab算法设计 - 谷速源码
下载频道> 资源分类> matlab源码> 算法设计> matlab虚拟环境 找到迷宫的最短路径源码程序

标题:matlab虚拟环境 找到迷宫的最短路径源码程序
分享到:

所属分类: 算法设计 资源类型:程序源码 文件大小: 17.39 KB 上传时间: 2019-12-01 22:17:26 下载次数: 57 资源积分:1分 提 供 者: jiqiren 20191201101806556
内容:
i=imread('arena03.bmp');
r=graythresh(i(:,:,1));
g=graythresh(i(:,:,2));
b=graythresh(i(:,:,3));
rm=r*255;
gm=g*255;
bm=b*255;
%extracting nodes and starting and end point
y=(i(:,:,1)>rm&i(:,:,2)>gm&i(:,:,3)==0);
g1=(i(:,:,1)==0&i(:,:,2)==255&i(:,:,3)==0);
r1=(i(:,:,1)==255&i(:,:,2)==0&i(:,:,3)==0);
b1=(i(:,:,1)==0&i(:,:,2)==0&i(:,:,3)==255);
ad=imadd(y,g1);
bw4=im2bw(ad);
ad2=imadd(bw4,r1);
%finding the centroid of lines as well as nodes and catenating both
%matrices
li=(i(:,:,1)==0&i(:,:,2)==0&i(:,:,3)==0);
[l,n]=bwlabel(ad2);
s=regionprops(l,'Centroid');
cen=cat(1,s.Centroid);
[m,n1]=bwlabel(li);
s1=regionprops(m,'Centroid');
ce=cat(1,s1.Centroid);
c=vertcat(cen,ce);
n2=n+n1;
%for k=1:n2
%text(c(k,1),c(k,2),int2str(k));
%end
%making a connection matrix
for v=1:n2
    for u=1:n2
        di=sqrt(((c(v,1)-c(u,1))^2)+((c(v,2)-c(u,2))^2));
        if di>=23&&di<=27
            a(v,u)=1;
        else
            a(v,u)=0;
        end
    end
end
%making a sparse matrix
sp=sparse(a);
[j,h]=bwlabel(r1);
s2=regionprops(j,'Centroid');
ct=cat(1,s2.Centroid);
 
%getting the label of red
for o=1:n
    if(ct(1,1)==cen(o,1))&&(ct(1,2)==cen(o,2))
        v1=o;
    end
end
[w,z]=bwlabel(g1);
s4=regionprops(w,'Centroid');
ct1=cat(1,s4.Centroid);
 
%geting the label of green
for u=1:n
    if(ct1(1,1)==cen(u,1))&&(ct1(1,2)==cen(u,2))
        v2=u;
    end
end
 
[dt,pa,pred]=graphshortestpath(sp,v1,v2,'Directed',false,'Method','BFS');
 
 
figure,image(i)
 
%plotting the path
for h=1:length(pa)-1
    hold on,plot([c(pa(h),1),c(pa(h+1),1)],[c(pa(h),2),c(pa(h+1),2)],'r','linewidth',3);
end

文件列表(点击上边下载按钮,如果是垃圾文件请在下面评价差评或者投诉):

关键词: matlab 虚拟 环境 迷宫 最短 路径 源码 程序

Top_arrow
回到顶部
联系方式| 版权声明| 招聘信息| 广告服务| 银行汇款| 法律顾问| 兼职技术| 付款方式| 关于我们|
网站客服网站客服 程序员兼职招聘 程序员兼职招聘
沪ICP备19040327号-3
公安备案号:沪公网安备 31011802003874号
库纳格流体控制系统(上海)有限公司 版权所有
Copyright © 1999-2014, GUSUCODE.COM, All Rights Reserved