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..,
1 次查看(过去 30 天)
显示 更早的评论
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);
0 个评论
采纳的回答
Kan-Hua
2013-12-11
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?
3 个评论
Image Analyst
2013-12-14
Why'd you accept it then? With my demo there is no such error. Check out my demos to see how it should be done.
Kan-Hua
2013-12-16
The error message happens because the function iamfreehand() is waiting for your response, but the user close the figure to end the program, so iamfreehand() function cannot return any output to hFH. This does not affect the program itself, but if you are really bothered by the error message, you can add a try/catch to catch that error message, like this:
close all;
ax=axes();
while true
try
hFH = imfreehand(ax); % Get the xy coordinates of where they drew.
xy = hFH.getPosition; % get rid of imfreehand remnant.
catch err
if strcmp(err.identifier,'images:roiParseInputs:invalidHandle');
disp('program exit');
break;
end
end
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
In Image Analyst's code, he set a dialog to ask whether the user want to continue in his main loop, so he can avoid this error message.
To Image Analyst: Thank you for your code though. I actually learned a lot from your code. :)
更多回答(1 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!