fitting the curve or line in 3d data and extendng the curve the end
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have the 3d data(attached), where the first two columns represent the xy coordinate of point in a image and third column is my image number. These images are slices of one volumetric image. I want to fit a straight line through these points and then extend the line in that direction. For instance my image starts from image number 36 and end at 128. i want to fit a line for these image points and then extend the line so that i ca get the coordinate of images from image 35 to 0.
1 commentaire
Matt J
le 28 Déc 2017
Didn't we cover this in your previous post?
I thought the problem was how to view the results.
Réponses (2)
Image Analyst
le 28 Déc 2017
Parameterize your equation on slice, then fit for x and y separately:
s = load('data.mat')
data = s.data
x = data(:, 1);
y = data(:, 2);
sliceNumber = data(:, 3);
coefficientsX = polyfit(sliceNumber, x, 1);
coefficientsY = polyfit(sliceNumber, y, 1);
sFitted = 1 : max(sliceNumber);
xFitted = polyval(coefficientsX, sFitted);
yFitted = polyval(coefficientsY, sFitted);
plot(sliceNumber, x, 'b*');
hold on;
plot(sliceNumber, y, 'c*');
plot(sFitted, xFitted, 'm-', 'LineWidth', 2);
plot(sFitted, yFitted, 'r-', 'LineWidth', 2);
grid on;
xlabel('Slice Number', 'FontSize', 20);
ylabel('x or y', 'FontSize', 20);
legend('x data', 'y data', 'x fit', 'yFit');
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/180439/image.png)
0 commentaires
Image Analyst
le 28 Déc 2017
If you want to ignore what seem to be like bad data with y < 3, then do this:
s = load('data.mat')
data = s.data
x = data(:, 1);
y = data(:, 2);
sliceNumber = data(:, 3);
goodRows = y > 3;
x = x(goodRows);
y = y(goodRows);
sliceNumber = sliceNumber(goodRows);
coefficientsX = polyfit(sliceNumber, x, 1);
coefficientsY = polyfit(sliceNumber, y, 1);
sFitted = 1 : max(sliceNumber);
xFitted = polyval(coefficientsX, sFitted);
yFitted = polyval(coefficientsY, sFitted);
plot(sliceNumber, x, 'b*');
hold on;
plot(sliceNumber, y, 'c*');
plot(sFitted, xFitted, 'm-', 'LineWidth', 2);
plot(sFitted, yFitted, 'r-', 'LineWidth', 2);
grid on;
xlabel('Slice Number', 'FontSize', 20);
ylabel('x or y', 'FontSize', 20);
legend('x data', 'y data', 'x fit', 'y Fit');
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/180445/image.png)
4 commentaires
Image Analyst
le 15 Juin 2018
I think he did, using my code. There is no reason that the code I gave should not work for his attached image once it has been segmented to give the (x,y) coordinates of the interface/boundary between the two regions. Now, finding that interface is a completely separate question than this one which regarded fitting/regression and extrapolation.
Eric Chadwick
le 18 Juin 2018
I understand that, but what I don't understand is how to fit just one line instead of two since I want the line of best fit in 3D (i.e. using x,y,z that than just x OR y and z.
Voir également
Catégories
En savoir plus sur Statistics and Machine Learning Toolbox dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!