Matlab中的融合向量

卡尔71

Matlab中,我有两个矩阵L1和L2,每行包含2D空间中几个点的坐标(行,列):

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

绘制后,我得到了这个:

红线为L1,蓝线为L2

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

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

-下一个:从(1,1)(或(8,7))开始,评估下一个点的方向。换句话说,点(2,2)从(1,1)开始的位置,点(3,3,)从(2,2)开始的方向,等等。并保存这些值。

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

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

-结果:如果前一阶段为TRUE,则融合纤维。如果为假,则不执行任何操作。

这里的一个关键点是建立一个参考,从中可以测量取向角。也许这种方法太复杂了。我猜有一种更简单的方式,更少的内存消耗方式。谢谢你。

迪卡卡(Divakar)

代码 -

% 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

希望这能解决!

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章