How can I designate an image which had been plot some points on to be an variable?

I've loaded an image BW. So imshow(BW) will open and show the image BW in the figure window.Then I use hold on and plot to draw some points on the image BW. How can I designate the image which contained the points to be an variable named BW1, that means use imshow(BW1) could get a picture of the original image (BW) WITH the points on it? PS: I don't want to save the picture which contained the points as an document like *.jpg,***.png, I just want to call up the picture in the following program. Below is the code I already have.
if true
%
figure;
lineall = false(size(BW));
imshow(lineall);
hold on
for i=1:3
vertexstep = cell2mat(vertex(i));
plot(vertexstep(:,1), vertexstep(:,2), 'w', 'LineWidth', 2)
end
hold off
end

Respuestas (1)

Thorsten
Thorsten el 17 de Nov. de 2015
Editada: Thorsten el 17 de Nov. de 2015
You can use the following function to draw a line in an image:
function I = bresenham(p1, p2, I)
%Draws a white line from P1 = [x1, y1] to P2 = [x2, y2] in gray-scale image
% I.
% Thorsten 2015-11-17
if nargin == 0
N = 100;
I = rand(N);
p1 = randi(N, [1 2]);
p2 = randi(N, [1 2]);
end
% http://www.cb.uu.se/~cris/blog/index.php/archives/400
d = p2-p1;
N = max(abs(d));
s = d/N;
%DP = p1;
%p = p1;
%for ii=1:N
% p = p+s;
% DP = [DP; round(p)];
%end
%for i = 1:size(DP, 1)
% I(DP(i,2), DP(i,1)) = 0;
%end
% vectorized version
DP = round(bsxfun(@plus, (0:N)'*s, p1));
ind = sub2ind(size(I), DP(:,2), DP(:,1));
I(ind) = 1;
if nargout == 0
imshow(I)
end

La pregunta está cerrada.

Preguntada:

el 17 de Nov. de 2015

Cerrada:

el 20 de Ag. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by