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!