Filter löschen
Filter löschen

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 Ansicht (letzte 30 Tage)
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);

Akzeptierte Antwort

Kan-Hua
Kan-Hua am 11 Dez. 2013
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 Kommentare
Image Analyst
Image Analyst am 14 Dez. 2013
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
Kan-Hua am 16 Dez. 2013
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. :)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Image Analyst
Image Analyst am 11 Dez. 2013
See my demos of imfreehand, attached.

Kategorien

Mehr zu Convert Image Type finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by