⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 compute_geodesic.m.svn-base

📁 fast marching method
💻 SVN-BASE
字号:
function path = compute_geodesic(D, x, options)% compute_geodesic - extract a discrete geodesic in 2D and 3D%%   path = compute_geodesic(D,x,options);%%   D is the distance map.%   x is the starting point.%   path is the shortest path between x and the starting point y (wich should%   satisfy D(y)=0).%%   Set options.method = 'discrete' if you want to use a pure discrete%   gradient descent.%%   Copyright (c) 2007 Gabriel Peyreoptions.null = 0;method = getoptions(options, 'method', 'continuous');if strcmp(method, 'discrete')    path = compute_discrete_geodesic(D,x);    return;endif size(x,1)>1 && size(x,2)>1    % several geodesics    if size(x,1)>3        x = x'; % probably user mistake of dimensions    end    path = {};    for i=1:size(x,2)        path{end+1} = compute_geodesic(D, x(:,i), options);    end    return;endif size(D,3)>1    % 3D    path = extract_path_3d(D,x,options);else    % 2D    path = extract_path_2d(D,x,options);endif size(path,1)>size(path,2)    path = path';end%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%function path = compute_discrete_geodesic(D,x)% compute_discrete_geodesic - extract a discrete geodesic in 2D and 3D%%   path = compute_discrete_geodesic(D,x);%%   Same as extract_path_xd but less precise and more robust.%%   Copyright (c) 2007 Gabriel Peyrend = 2;if size(D,3)>1    nd = 3;endx = x(:);path = round(x(1:nd));% admissible movesif nd==2    dx = [1 -1 0 0];    dy = [0 0 1 -1];    dz = [0 0 0 0];    d = cat(1,dx,dy);    vprev = D(x(1),x(2));else    dx = [1 -1 0 0 0 0];    dy = [0 0 1 -1 0 0];    dz = [0 0 0 0 1 -1];    d = cat(1,dx,dy,dz);    vprev = D(x(1),x(2),x(3));ends = size(D);while true    x0 = path(:,end);    x = repmat(x0,1,size(d,2))+d;    if nd==2        I = find(x(1,:)>0 & x(2,:)>0 & x(1,:)<=s(1) & x(2,:)<=s(2) );        else        I = find(x(1,:)>0 & x(2,:)>0 & x(3,:)>0 & x(1,:)<=s(1) & x(2,:)<=s(2) & x(3,:)<=s(3) );    end    x = x(:,I);    if nd==2        I = x(1,:) + (x(2,:)-1)*s(1);    else        I = x(1,:) + (x(2,:)-1)*s(1) + (x(3,:)-1)*s(1)*s(2);    end    [v,J] = min(D(I));    x = x(:,J);    if v>vprev        return;    end    vprev = v;    path(:,end+1) = x;end%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%function path = extract_path_2d(A,end_points,options)% extract_path_2d - extract the shortest path using %   a gradient descent.%%   path = extract_path_2d(D,end_point,options);%%   'D' is the distance function.%   'end_point' is ending point (should be integer). %%   Copyright (c) 2004 Gabriel Peyr

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -