get position of imfreehand

4 ビュー (過去 30 日間)
mary
mary 2011 年 6 月 15 日
回答済み: Tim Jackman 2018 年 9 月 27 日
hi, how can i get the position of a drawn freehand, and after it i can draw the same freehand again by that position. i got the position by getposition, but i can't draw it again!!! plz help me tnx

採用された回答

Alex Taylor
Alex Taylor 2011 年 6 月 15 日
Hi Mary,
Unfortunately, the current design of imfreehand doesn't allow programmatic placement of the tool given a set of vertices as input. This is a known enhancement request from other users.
If you want to query the position of any of the ROI tools in the toolbox, you should use the method getPosition (as you suggested) and avoid digging around in the HG innards of the tool.
imshow('pout.tif');
h = imfreehand;
pos = h.getPosition();
As a workaround, you could achieve approximately the effect you are looking for by creating an instance of impoly given the position of your freehand tool. If you use the setVerticesDraggable method of impoly, it will visually appear identical to imfreehand.
h_poly = impoly(gca,pos);
h_poly.setVerticesDraggable(false);
Hope this helps.
  1 件のコメント
Abdul-Rauf Mujahid
Abdul-Rauf Mujahid 2013 年 10 月 8 日
編集済み: Abdul-Rauf Mujahid 2013 年 10 月 8 日
imfreehand draws continuous figure. can i draw a discrete figure using dots/points like impoint?

サインインしてコメントする。

その他の回答 (2 件)

Andrew Newell
Andrew Newell 2011 年 6 月 15 日
The output of imfreehand is chopped up into a few children (I don't know why), so you have to dig a bit to get the data. Here is a demo:
figure
subplot 211
h = imfreehand; % Draw your doodle here
hc = get(h,'Children');
XData = []; YData = [];
for ii=1:length(hc)
x = get(hc(ii),'XData');
y = get(hc(ii),'YData');
XData = [XData; x(:)];
YData = [YData; y(:)];
end
subplot 212
plot(XData,YData)
  1 件のコメント
Raymundo Dominguez
Raymundo Dominguez 2016 年 5 月 27 日
I found your code very helpful; I would like to comment something about the x,y outputs: even for a very small free drawing line (for example from coordinates (1,1) to (4,5) of the image), the length of these vectors are too big; 85 points each one in this example. Do you know which is the reason for that? Thanks in advance.

サインインしてコメントする。


Tim Jackman
Tim Jackman 2018 年 9 月 27 日
The new drawfreehand ROI supports get/set for Position:
For example, we can draw a freehand shape, and then update the position:
imshow('peppers.png')
h = drawfreehand;
% Shift the position down and to the right by 50 pixels
h.Position = h.Position + 50;

Community Treasure Hunt

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

Start Hunting!

Translated by