How to draw a line through a set of points?

조회 수: 22 (최근 30일)
valerio auricchio
valerio auricchio 2020년 11월 3일
댓글: Rik 2021년 6월 10일
Hi, I have an image and a set of points present in the image. These points are not aligned with each other and I would like to draw a line that intersects the points
  댓글 수: 3
Rik
Rik 2020년 11월 3일
question continued here
@Valerio: please don't open a new equivalent question.
John D'Errico
John D'Errico 2020년 11월 3일
PLEASE DON'T ASK THE SAME QUESTION REPEATEDLY!
I've deleted my answer. since you already have answers to your last question.

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

채택된 답변

Image Analyst
Image Analyst 2020년 11월 3일
You forgot to attach your points, which would have been helpful.
Since your definition of "through" is a regression rather than to have the line connect all the points, use polyfit()
coefficients = polyfit(x, y, 1);
%xFit = x; % Option 1 : same number of points as the training set.
xFit = linspace(min(x), max(x), 2000); % Option 2 : lots of points, and not just where the training points are.
yFit = polyval(coefficients, xFit);
plot(x, y, 'r+', 'LineWidth', 2, 'Markersize', 15)
hold on;
plot(xFit, yFit, 'm-', 'LineWidth', 2)
  댓글 수: 7
Image Analyst
Image Analyst 2020년 11월 3일
편집: Image Analyst 2020년 11월 3일
Please attach your original image without the cyan markers on it, so I can get the points via thresholding:
mask = grayImage >= 200;
[y, x] = find(mask);
hold on
plot(x, y, 'c.');
hold off;
or else, supply me with a list of the x,y points you want to use.
And tell me the definition of the other line so I can find the angles of both of them and the acute angle between them.
valerio auricchio
valerio auricchio 2020년 11월 3일
No it's all right i find what i nedd thanks a lott!!1

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

추가 답변 (1개)

Ameer Hamza
Ameer Hamza 2020년 11월 3일
If you have the coordinates then you can use plot()
img; % your image
x; % x-coordinates of points
y; % y-coordinates of points
imshow(img);
hold on
plot(x, y)
  댓글 수: 6
Aniket Agrawal
Aniket Agrawal 2021년 6월 10일
how can i store that curve produced using plot(x,y) in a variable.
Rik
Rik 2021년 6월 10일
You can store a handle to the graphics object. Is that what you mean by storing the curve?

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by