How to find the center / "rdige" of two loops that are given as x / y coordinates?

I have a problem that I think is pretty simple, but I'm stuck. Help will be appreciated.

I have two structure contours that are closed, but not circular, like the x / y coordinates. One of them is completely in the zone of the other, so they do not intersect and have different lengths (they think of two deformed, concentric circuses). My goal is to find a line that traces the middle of two lines, such as a ridge between them. I tried different approaches (for example, using rotating lines, determining intersections and taking the average of two coordinates). I have a feeling that it’s not difficult and maybe even some kind of built-in method, but I just can’t find a solution ...

Thank you for your help!

edit: something like an attached image - blue and red are two contours, green is my (manual;)) inserted center line.

Image example

+4
source share
2 answers

The general approach, which should work regardless of whether you have outlines of points in regular grids (for example, in your example) or not, is as follows. I will start with a set of coordinate points for the inner polygon ( xInnerand yInner, 18 points) and the outer polygon ( xOuterand yOuter, 22 points) selected from the square of the unit of measure:

plot(xOuter([1:end 1]), yOuter([1:end 1]), 'b*-');
hold on;
plot(xInner([1:end 1]), yInner([1:end 1]), 'r*-');

enter image description here

, meshgrid, , griddata ( 1 2 ) contour, 1.5:

[X, Y] = meshgrid(linspace(0, 1, 101));
Z = griddata([xInner; xOuter], ...
             [yInner; yOuter], ...
             [2.*ones(size(xInner)); ones(size(xOuter))], X, Y);
[C, H] = contour(X, Y, Z, [1.5 1.5]);

enter image description here

C.

+2

:

(X1, Y1) 1

(X2, Y2) 2

1, 1 2 , d=min(sqrt((X2-X1)^2+(Y2-Y1)^2)).

theta=atan2((Y1-Y2)/(X1-X2)).

, , , ...

: @m7913d , X1, Y1 X2, Y2, avg, X3, Y3 , ... ...

:

enter image description here

c=fspecial('gaussian',51,5);
c1=edge(c>1e-3);
c2=edge(c>1e-4);
[x1 y1]=find(c1);
[x2 y2]=find(c2);

for n=1:numel(x2)
         [val id]=min(sqrt((x2(n)-x1).^2+(y2(n)-y1).^2));
         x3(n)=(x2(n)+x1(id))/2;
         y3(n)=(y2(n)+y1(id))/2;
end

imagesc(c2+c1*2); hold on
plot(y3,x3,'w.');
+1

Source: https://habr.com/ru/post/1680237/


All Articles