fitting the curve or line in 3d data and extendng the curve the end
7 views (last 30 days)
Show older comments
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 Comment
Matt J
on 28 Dec 2017
Didn't we cover this in your previous post?
I thought the problem was how to view the results.
Answers (2)
Image Analyst
on 28 Dec 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');
0 Comments
Image Analyst
on 28 Dec 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');
4 Comments
Image Analyst
on 15 Jun 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
on 18 Jun 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.
See Also
Categories
Find more on Statistics and Machine Learning Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!