Superposition of a line between 2 point in a image

1 次查看(过去 30 天)
I have an image of a person. I have the coordinates (in pixel) of the 2 points of his shoulder. I would like to superimpose a line between these 2 points on the image.
Is it possible? Thank you in advace.

回答(1 个)

Image Analyst
Image Analyst 2020-7-15
Yes. If you want it in the overlay:
hold on;
line([col1, col2], [row1, row2], 'Color', 'r', 'LineWIdth', 2);
% Or x,y version: line([x1, x2], [y1, y2], 'Color', 'r', 'LineWIdth', 2);
hold off;
If you want it burned into the image, you'll have to use polyfit() and polyval() to get all the coordinates in between the endpoints and then have a loop where you write those into the image.
coefficients = polyfit([x1, x2], [y1, y2], 1);
xFit = min([x1,x2]) : max([x1,x2]);
yFit = polyval(coefficients, xFit);
for k = 1 : length(xFit)
thisRow = round(yFit(k));
thisCol = round(xFit(k));
grayImage(thisRow, thisCol) = 255; % Or whatever intensity you want.
end
  2 个评论
Luigi Stragapede
Luigi Stragapede 2020-7-17
Thanks a lor for you answer.
I have another problem. I know the coordinates in pixel of the 2 points of the shoulder and I have built the line which connects these 2 points using 'hold on' as you said.
But it seems that the 2 figures (that is the image and the reference system where the line is plotted) have different scale since the line doesn't appear on the right position.
Image Analyst
Image Analyst 2020-7-17
That's shouldn't happen. Please supply the original image, and the coordinates in row,column format that the endpoints of the line are at, and your code for reading in and placing that line onto the image.

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by