MATLAB Answers

smoothing 2D scattered points

22 views (last 30 days)
Hi Friends,
Is there anyway to smooth 2D scattered points?
I drew my question in this picture:
on the left we have an scattered path of points, but, rationally one can think of a smoothed representing set of points (black dots) in the right picture.
Thank you very much.

Accepted Answer

Image Analyst
Image Analyst on 9 Feb 2021
Yes. You can use something like spline or sgolayfilt() to smooth both the x and y coordinates independently. See attached demo. Here is the main part:
% Now smooth with a Savitzky-Golay sliding polynomial filter
windowWidth = 45
polynomialOrder = 2
smoothX = sgolayfilt(x, polynomialOrder, windowWidth);
smoothY = sgolayfilt(y, polynomialOrder, windowWidth);
Attach your x and y data if you can't figure it out from the well commented demo code.
  4 Comments
Alireza Ahani
Alireza Ahani on 9 Feb 2021
oh, I saw the "bwskel" you mention, that is so much interesting,
Highly likely it is the solution for this problem.
Thank you very much @Image Analyst . God bless.

Sign in to comment.

More Answers (1)

KSSV
KSSV on 9 Feb 2021
Read about polyfit.
  1 Comment
Alireza Ahani
Alireza Ahani on 9 Feb 2021
Hi,
an injective function can not be fitted into this type of data (X1--->Y1 && X1--->Y2).
smoothing seems to be the only remedy.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!