MATLAB : How to find the line of best fit through a binary image?

Click For Summary

Discussion Overview

The discussion revolves around finding the line of best fit through a binary image derived from a 2D Fourier transform. Participants explore methods to achieve this, particularly focusing on the challenges posed by having multiple y values for each x value in the dataset.

Discussion Character

  • Technical explanation, Debate/contested, Mathematical reasoning

Main Points Raised

  • One participant seeks a method to find the line of best fit through the longest axis of a binary image.
  • Another participant suggests using the polyfit() function in MATLAB for best fit lines, specifying the need for xdata and ydata vectors.
  • A concern is raised about polyfit() requiring unique xdata points, as the current dataset has multiple y values for each x value.
  • One participant proposes averaging repeated xdata points to create two vectors suitable for polyfit(), suggesting that this might yield reasonable results despite their lack of statistical expertise.
  • Another participant mentions that linear regression can be used even when there are multiple y values for the same x value, and introduces the concept of principal component analysis as an alternative approach.

Areas of Agreement / Disagreement

Participants express differing views on the best approach to handle multiple y values for each x value, with some supporting the use of averaging and others advocating for linear regression or principal component analysis. No consensus is reached on a single method.

Contextual Notes

The discussion highlights the limitations of polyfit() in handling repeated xdata points and the potential need for data transformation before applying fitting methods. The effectiveness of averaging or using alternative methods like linear regression or principal component analysis remains uncertain.

Who May Find This Useful

Readers interested in MATLAB data analysis, statistical methods for fitting lines to data, and image processing techniques may find this discussion relevant.

tbeta006
Messages
3
Reaction score
0
I have found the 2D Fourier transform of a figure and then changed it to a binary image (attached).

I want to find the line of best fit through the longest "axis"? of this figure. What would be the simplest way to accomplish this?
 

Attachments

  • BinaryImage.PNG
    BinaryImage.PNG
    8.5 KB · Views: 869
Physics news on Phys.org
You can use polyfit() for best fit lines:

Code:
p = polyfit(xdata, ydata, N)

xdata: the x-axis values
ydata: the function values corresponding to the values in xdata
N: degree of the fitFor a linear fit, use N = 1.
 
Wouldn't polyfit require vectors for each data set? right now I have multiple y values for each x value.
 
Yes you're absolutely right. I just looked quickly; polyfit doesn't work when there are repeated (or nearly repeated) xdata points.

Is it feasible to average all of the repeated xdata points so that you just have 2 vectors with 1 function value for each x value? Then you can use polyfit with that data set. It seems to me like it might produce something reasonable, but I'm not a statistics expert.

If so, you can use accumarray to perform the averaging.
 
That should work since the figure is symmetrical, I'll give it a shot. Thanks
 
If you are talking about a linear line, you can calculate the linear regression of Y as a function of X. Because it works when random errors are added to Y, there can be multiple Y values for the same X value. Alternatively, the principle component that can be calculated through the data set.
 

Similar threads

  • · Replies 12 ·
Replies
12
Views
7K
  • · Replies 14 ·
Replies
14
Views
4K
  • · Replies 15 ·
Replies
15
Views
2K
  • · Replies 2 ·
Replies
2
Views
4K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K