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.
0 个评论
回答(1 个)
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 个评论
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!