fitting the curve or line in 3d data and extendng the curve the end
4 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
Matt J
2017 年 12 月 28 日
Didn't we cover this in your previous post?
I thought the problem was how to view the results.
回答 (2 件)
Image Analyst
2017 年 12 月 28 日
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 件のコメント
Image Analyst
2017 年 12 月 28 日
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 件のコメント
Image Analyst
2018 年 6 月 15 日
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
2018 年 6 月 18 日
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.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!