5

I have a set of points that I need to group using their vicinity to the respective sinusoidal lines. I tried to determine the lines using a standard Hough transform, but that doesn't solve the problem (only a few lines are detected).

I'd like to test if RANSAC would work better to detect the various sin curves. Do you have an example for a similar algorithm?

I know that RANSAC is not the best tool to find multiple lines, so what I would do is a) find the function fitting most points; b) iterate the search, considering only the remaining ones.

enter image description here

albus_c
  • 6,292
  • 14
  • 36
  • 77
  • 3
    If you are fitting a `sin(x)` to your data, that yellow line is definitely not missing. The "bottom" and "top" parts of the sin definetly dont correspond to the same frequency `sin(X*fs)`. – Ander Biguri Jun 16 '15 at 15:42
  • Agree with @AnderBiguri - If you want to get that line, you'd have to run RANSAC on multiple frequencies to capture the one in yellow. The lines in blue most likely belong to one frequency. – rayryeng Jun 16 '15 at 15:46
  • @rayryeng not only different frequencies, but the shape itself can not be captured by a simple sin. The values between 120-160 "turn" very fast, while the values between 40-120 very slow. A sin will not fit that yellow area I think. – Ander Biguri Jun 16 '15 at 16:06
  • 1
    @AnderBiguri - Almost looks like a polynomial expression... then again, the `sin` function could be interpreted as an infinite sum of polynomials anyway! – rayryeng Jun 16 '15 at 16:07
  • I agree there is something very strange. I'll think more on why I have those almost aligned points not belonging to any fit line. – albus_c Jun 16 '15 at 16:41
  • @albus_c Make sure that you understand how Hough transform works. You will have an accumulator array in parameter space, in that array you will have local maxima. Now the blue lines are bins of that array that belong to the same , high local maximum. The yellow points would correspond to the second maximum. You would either want to do the suppression of the first maximum, or just return more (than three) sinusoids from the Hough transform. Try the latter to see if I'm right (like 50 sinusoids), then try the former because it'll give you more sensible results – Hennadii Madan Sep 10 '15 at 20:16

1 Answers1

0

RANSAC

The algorithm

Until an inlier percentage threshold is reached or N sample combinations are tested.

  • It randomly selects the smallest sample as possible to build or fit a model.
  • The other data points are classified as inliers or outliers
  • The model is accepted or rejected

Inputs:

  • error tolerance for determining inliers and outliers
  • Threshold inlier percentage
  • Maximum sample combinations tested

Possible improvements

  • Make sure that no combination is tested more than once
  • If a better way is possible to select combinations, use that.
  • Once a lot of inliers are found, use a new set of inliers for the further search

Source: Fischler and Bolles - Random Sample Consensus: A Paradigm for Model Fitting with Applications to Image Analysis and Automated Cartography

Your aplication

Your model is a sine defined as f(x) = amplitude * sin(period * x) + bias. Fitting this model will not be as easy as it is dependent on three parameters. I think that it will risk in long runs and a possibility of overfitting. A possible solution might be to run the algorithm multiple times for different periods and keep the bias and amplitude fixed.

iterationThreshold = 10000;
iterationCount = 0
errorthreshold = 0.05;

while(numel(inliers(:,1)) > inlierThreshold)

   samples = extractMinimumSamples(points);
   [sineX, sineY] = fitSine(samples);
   inliers = determineInliers(points, SineX, SineY)

   iterationCount = iterationCount + 1;

   if(iterationCount => iterationThreshold)
      break;
   end

end  

See also the possible improvements for modifications to this code

pvl
  • 194
  • 1
  • 10