MATLAB: Hi,, i’m new in matlab.. i want to draw using the mouse with this code, but this code can only make one line,, i want to make it more..,

imageimage processing

hFH = imfreehand (); % Get the xy coordinates of where they drew.
xy = hFH.getPosition; % get rid of imfreehand remnant.
delete(hFH); % Overlay what they drew onto the image.
hold on; % Keep image, and direction of y axis.
x = xy(:, 1);
y = xy(:, 2);
% X = [X x];
% Y = [Y y];
line(x, y, 'Color','k','LineWidth', 4);

Best Answer

Hi,
The simplest way is initialising an axes object that imfreehand() function can draw on to, and put your function into an infinite loop, like this:
ax=axes();
while true
hFH = imfreehand(ax); % Get the xy coordinates of where they drew.
xy = hFH.getPosition; % get rid of imfreehand remnant.
delete(hFH); % Overlay what they drew onto the image.
hold on; % Keep image, and direction of y axis.
x = xy(:, 1);
y = xy(:, 2);
% X = [X x];
% Y = [Y y];
line(x, y, 'Color','k','LineWidth', 4);
end
Is this what you are looking for?