Question

In Matlab I've got two matrices,L1 and L2, containing in each row the coordinates (row, column) of several points in 2D space:

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

After plotting I've got this:

Red line is L1 and blue one represents L2

I'm trying to implement an algorithm that could fusion lines that are similarly orientated. I've tried for quite a while. I guess that the simplest way of solving this is to follow these steps:

-First: suppose that L1 and L2 are two segments of the same line(L3).

-Next: Starting from (1,1) (or (8,7)) evaluate the orientation of the next point. In other words, the orientation that point (2,2) has from (1,1), point (3,3,) from (2,2), etc. And save those values.

-Next: Calculate from all orientation values the average value.

-Next: evaluate if the fusion points between fibers, that in this case are (3,3) and (4,4), follow a similar orientation.

-Results: If previous stage is TRUE, then fusion the fibers. If FALSE, do nothing.

One key point here is to establish a reference from which orientation angles can be measured. Maybe this approach is too complicated. I guess there is a simpler way and less memory consuming way. Thank you.

Was it helpful?

Solution

Code -

% 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

Hope this settles it!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top