Smoothing 2D Contours Using Local Regression Lines
A contour of a 2D region is defined by an ordered set of points where the neighboring elements contain the neighboring points. Such representation can be obtained with many techniques such as boundary tracing and chain codes. (In a simple 2D point set or a curve the points do not have to lie in a specific order.)
The contour smoothing is done by projecting all the contour points onto the local regression line. For each point, N neighboring points which lie on the contour are sampled on each side and a local regression line is computed. Then the current point is projected on this line. Applying this algorithm to all the points smooths the contour and in a way brings the points closer. 2N+1 is the number of total points contributing to the computation of the local regression line. The higher the number of points, the smoother the curve.
Because of the linear nature of fitting, when too much smoothing is desired, the algorithm loses important features such as corners, and gets confused in such critical regions. This in a way is a wrong over-smoothing. A way to be less prone to such errors is to use gaussian weighted least squares fit. For this purpose I use Andrey Sokolov's line fitting. Here is the link:
http://www.mathworks.com/matlabcentral/fileexchange/28894-weighted-orthogonal-least-squares
In the test code, a contour is obtained using chain codes (bwtraceboundary) and smoothed. The example is taken from a real application
Zitieren als
Tolga Birdal (2024). Smoothing 2D Contours Using Local Regression Lines (https://www.mathworks.com/matlabcentral/fileexchange/30793-smoothing-2d-contours-using-local-regression-lines), MATLAB Central File Exchange. Abgerufen.
Kompatibilität der MATLAB-Version
Plattform-Kompatibilität
Windows macOS LinuxKategorien
- AI and Statistics > Curve Fitting Toolbox > Linear and Nonlinear Regression >
- AI and Statistics > Curve Fitting Toolbox > Smoothing >
Tags
Quellenangaben
Inspiriert von: Weighted Orthogonal Least Squares
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Live Editor erkunden
Erstellen Sie Skripte mit Code, Ausgabe und formatiertem Text in einem einzigen ausführbaren Dokument.
Version | Veröffentlicht | Versionshinweise | |
---|---|---|---|
1.2.0.0 | Description updated |
||
1.1.0.0 | Now uses Andrey Sokolov's Weighted Orthogonal Least Squares fit, with gaussian weighting. This is smoother, more robust and less prone to sudden changes such as corners. (If gaussian weighting is not used, it's also faster). |
||
1.0.0.0 |