fitting the curve or line in 3d data and extendng the curve the end

조회 수: 6 (최근 30일)
prashant singh
prashant singh 2017년 12월 28일
댓글: Eric Chadwick 2018년 6월 18일
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.

답변 (2개)

Image Analyst
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');

Image Analyst
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
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
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by