How can I try the parametric border of an object through N points, which leads to equal parts of the length of the arc?

The parametric border of an object can be retrieved in Matlab using the bwtraceboundary function. It returns a Q-by-2 matrix B, where Q is the number of boundary pixels for the object, and the first and second columns store the coordinates of the rows and columns of boundary pixels, respectively.

I want to make a sampling of this border of Q elements through N points that divide the original border in segments of equal arc length.

A straightforward solution, which I thought was to calculate the length L of the border by summing the distance between two adjacent border pixels. These distances are 1 or sqrt (2). Then I divide L by N to find the desired length of the arcs. Finally, I iterate over the border, again summing the distance between two adjacent border pixels. When the sum is greater than or equal to the required arc length, the current boundary pixel is selected as one of N, which will constitute a discrete boundary.

This is a good decision? Is there a more efficient / simpler solution?

+4
source share
1 answer

Over the years, I have seen this question, it would seem, a huge number of times. So I wrote a small tool that will do just that. Draw a piecewise linear or even curvilinear (spline) arc in the total number of measurements so that consecutive points are at an even or predetermined distance along this arc.

In the case of using only piecewise linear arcs, this is quite easy. You sum the total length of the arc of the curve, then interpolate along the length of the arc, but since this is known to be piecewise linear, it only requires linear interpolation along this length as a function of the cumulative length of the arc.

In the case of a curved arc, it is easiest to do as a solution to a system of ordinary differential equations by observing events along this path. ODE45 does it beautifully.

You can use interparc as described in MATLAB Central File Exchange to do this for you, or if you want to learn how to do it yourself for a simple piecewise linear case, read the first part of the code, where I do piecewise linear interpolation of the arc length. It is good that the linear case is executed in a fully vectorized form, so explicit loops are not needed.

+5
source

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


All Articles