What is the best way to draw a line over a black and white (binary) image in MATLAB, provided the start and end coordinates are known?
Please note, I am not trying to add an annotation line, I would like the line to become part of the image.
What is the best way to draw a line over a black and white (binary) image in MATLAB, provided the start and end coordinates are known?
Please note, I am not trying to add an annotation line, I would like the line to become part of the image.
You may want to look at my answer to an SO question about adding a line to an image matrix. Here's a simpler example than the one I have in that answer, which will make a white line running from row and column index (10,10) to (240,240):
img = imread('cameraman.tif'); %# Load a sample black and white image
[r,c] = size(img); %# Get the image size
rpts = linspace(10,240,1000); %# A set of row points for the line
cpts = linspace(10,240,1000); %# A set of column points for the line
index = sub2ind([r c],round(rpts),round(cpts)); %# Compute a linear index
img(index) = 255; %# Set the line points to white
imshow(img); %# Display the image
And here's the resulting image: