0

I'm reading data from a sensor. The sensor give an array of points (x,y). But as you can see in the image, there is a lot of noise:

point cloud with noise.

I need to clean the data in a way that the data filtered, give a few points . Using something like Median,adjacent averaging, mean of the xy points or an algorithm that removes the noise. I know that there are a bunch of libraries in Python that make the work automatically. All the auto libraries that I found are base on image analysis and I think they do not work for this case because this is different, these are points (x,y) in a dataset.

point-cloud noise cleaned:

point-cloud noise cleaned

PD: I wanted to do the median of the points but i got confused when i tried with an bidimensional array (this mean ListOfPoints[[x,y],[x,y],[x,y],[x,y],[x,y],[x,y]]) I didn't know how to make that calculation with for or while to iterate and make the calc. I prefer C#, but if there is a solution in other language without libraries, I would be open to it.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
edu7
  • 3
  • 3
  • Welcome to Stack Overflow. Requests for referrals to libraries and other resources aren't on topic here. Please [edit] your question to be more specific. – O. Jones Oct 21 '22 at 19:05
  • I already described the filtering in [here](https://stackoverflow.com/a/74121170/2521214) – Spektre Oct 22 '22 at 07:13

2 Answers2

0

One of the methods you can use is k_means algorithm. This picture briefly explains this algorithm k_means

This link fully explains the k_means algorithm. Also, how to create a loop on the input data. I don't think any additional explanation is needed k_means algorithm

K_menans algorithm is very simple and you will understand it with the first Google search

Hossein Sabziani
  • 1
  • 2
  • 15
  • 20
  • I think that K means worths only if I know the number of clusters to classify the data – edu7 Oct 31 '22 at 23:17
0

You could try doing a weighted average of the Y-value at sampled X-positions. Something like this:

List<Point2> filtered_points = new List<Point2>();
for (int x = xmin; x <= xmax; x++)
{
    double weight_sum = 0;
    List<double> weights = new List<double>();
    foreach (Point2 p in point_list)
    {
        double w = 1.0/((p.x - x)*(p.x - x) + 1e-3);
        weights.Add(w);
        weight_sum += w;
    }

    double y = 0;
    for (int i = 0; i < point_list.Count; i++)
    {
        y += weights[i]*point_list[i].y / weight_sum;
    }
    filtered_points.Add(new Point2(x, y));
}

You would probably need to tune the weights to get nice results. Also, in the example I am using a quadratic decay, but other weighting functions can be used (linear decay, gaussian function...)

leandro
  • 167
  • 8