【问题标题】:Fusion Vectors in MatlabMatlab中的融合向量
【发布时间】:2014-03-02 20:32:19
【问题描述】:

Matlab 中,我有两个矩阵 L1 和 L2,每行包含二维空间中多个点的坐标(行、列):

L1=[1,1;2,2;3,3];
L2=[4,4;5,5;6,5;7,6;8,7];

绘制后我得到了这个:

我正在尝试实现一种算法,该算法可以融合方向相似的线条。我已经尝试了一段时间。我想解决这个问题的最简单方法是按照以下步骤操作:

-首先:假设L1和L2是同一条线(L3)的两段。

-Next:从 (1,1) (或 (8,7)) 开始计算下一个点的方向。换句话说,点 (2,2) 的方向来自 (1,1),点 (3,3,) 来自 (2,2) 等。并保存这些值。

-下一步:从所有方向值计算平均值。

-下一步:评估纤维之间的融合点,在这种情况下是 (3,3) 和 (4,4),是否遵循类似的方向。

-结果:如果前一阶段为真,则融合光纤。如果为 FALSE,则什么也不做。

这里的一个关键点是建立一个可以测量方位角的参考。也许这种方法太复杂了。我想有一种更简单的方法和更少的内存消耗方法。谢谢。

【问题讨论】:

    标签: matlab matrix orientation line


    【解决方案1】:

    代码-

    % We need to set a tolerance value for the similarity of slopes between the
    % main data and the "fusion" data. This tolerance is in degrees, so basically
    % means that the fiber must be within TOL degrees left or right of the overall data average.
    TOL = 10;
    
    % Slightly different and a more general data probably
    L1=[2,3;3,5;4,10];
    L2=[7,15;8,19;9,21];
    L_fiber = [L1(end,:);L2(1,:)];
    
    % Slopes calculation
    a1 = diff(L1);
    m1 = a1(:,2)./a1(:,1);
    
    a2 = diff(L2);
    m2 = a2(:,2)./a2(:,1);
    
    % Overall slope for the main data
    m = mean([m1;m2]);
    
    a_fiber = diff(L_fiber);
    m_fiber = a_fiber(:,2)./a_fiber(:,1);
    m_fiber_mean = mean(m_fiber);
    
    % Checking if the fiber mean is within the limits set by TOL
    deg_max = atan(m)*(180/pi) + TOL;
    deg_min = atan(m)*(180/pi) - TOL;
    
    slope_max = tan(deg_max*pi/180);
    slope_min = tan(deg_min*pi/180);
    
    if m_fiber_mean >= slope_min && m_fiber_mean <= slope_max
        out = true;
        disp('Yes the fusion matches the overall data');
    else
        out = false;
        disp('No the fusion does not match the overall data');
    end
    

    希望这能解决!

    【讨论】:

    • 哇!真是令人印象深刻!我在想如何使用线条的斜率,但我不知道该怎么做。谢谢你这么快的回复。现在我正在用更复杂的行尝试你的代码,让我们看看它是如何工作的......
    • 为更好地使用相似度容差而进行了编辑。
    • 所以 TOL 现在是度数?
    • 是的,如代码中所述。对更改感到抱歉,为了更易于理解的代码和用法需要它。
    • 哦!是的,我没读过。谢谢!我对此感到非常沮丧。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-28
    • 1970-01-01
    相关资源
    最近更新 更多