从另一个

时间:2017-02-08 08:44:48

标签: matlab matrix

我是从图像的骨架开始工作的。想要填充一些不完整的分支,我提取了骨架的终点并实现了Dijkstra的算法,以找到点之间的最小路径(我得到一个矩阵FR 500x500)。

我应用了成本和方向的约束来限制不良连接。我的问题是我仍然有不需要的链接,因为一些起点属于不同成本的几条路径。然后我提取了这些起点,只保留成本最低的那些(矩阵P 75x3,第1列和第2列是起点的坐标X和Y,第3列是成本)。

我现在尝试编码,我想采取所有可能的路径,那些有起点和成本对应于矩阵FP,但我不知道该怎么做。

我想在此代码中指出每个起点都有“权利”,只采用最便宜的路径

NumberPath = 0;
S=size(EP); %EP = matrix 90x2 coordinates x and y of skeleton's end points 
NumP=S(1);

for i=1:NumP-1
    for j=i+1:NumP
        FP = ED(i,:);
        LP = ED(j,:);
        [cost,path] = dijkstra(PC,Weight); % PC = matrix of all possible paths
        dimPath = size(path);

        dx=LP(1)-FP(1);
        dy=LP(2)-FP(2);

        if dx>0 && dx/dy>0 % Constraints of orientation

           NumberPath = NumberPath+1;

    if (cost<55) % Constraints of Cost
    for p=1:dimPath(2)
        FR(PC(path(1,p),2),PC(path(1,p),1))=NumberPath; 
   % FR=Matrix 500x500 with all paths according to conditions 

        Cost(i,j)=cost;            % Matrix of all cost < 55

         P(NumberPath,:)=FP;      % Starting Point of each path
         L(NumberPath,:)=LP;      % End Point of each path

   end
        end
   end
end

0 个答案:

没有答案
相关问题