Precise contour finding algorithm in Python

519 views Asked by At

My task at hand is finding specific contours in a cloud of points. They need to be determined as accurately as possible. Therefore higher order polynomial interpolation must be used. I have data consisting of points in a grid, each point having its own height.

I had great success finding contours with matplotlib.contours function. Then I directly used matplotlib.cntr (C++ algorithm) to determine specific contours. But because the file uses marching squares algorithm (linear interpolation) the precision of found contours is not good enough.

I am looking for alternative ways to solve this problem. A suggested solution was to

  • Use bicubic interpolation to find analytical function around a specific point.
  • Followed by calculation of the function derivative.
  • Derived function is then used to determine direction in which derivative stays at 0 (using point as a point of view). By moving a small distance in that direction height should remain constant.

Using this algorithm a contour should be found. Would this algorithm work, can I take any shortcuts when implementing it (by using already implemented functions)?

Implementing this algorithm would take quite the effort on my part, and besides it may only work in theory. I am guessing that the numerical error should still be present (the derivative may not be exactly 0) and may in the end even surpass the current one (using marching squares). I want to consider other, easier and faster methods to solve this problem.

What other algorithm could be used to solve it?

Did anyone ever face a similar problem? How did you solve it?

0

There are 0 answers