draw straight line between x1y1 and x2y2 in image in matlab

To draw a straight line between two points in an image using MATLAB, you can use the line function. Here's the code snippet to do so:

main.m
% Read the image
img = imread('image.jpg');

% Plot the image
imshow(img);

% Define the points
x = [x1, x2];
y = [y1, y2];

% Draw the line
line(x, y, 'Color', 'r', 'LineWidth', 2);
183 chars
13 lines

In this code, replace x1, y1, x2, and y2 with the pixel coordinates of the two points between which you want to draw a line. You can also adjust the color and thickness of the line by changing the values of the Color and LineWidth parameters in the line function.

gistlibby LogSnag