Drawing with mouse motion in a GUI-image

5 ビュー (過去 30 日間)
ImageProcNaive
ImageProcNaive 2016 年 7 月 18 日
コメント済み: ImageProcNaive 2016 年 9 月 3 日
Hi, I want to draw a line in an image displayed in a GUI. Matlab has a good example which works great for an individual figure:
However, while running it from a callback function in the GUI, I am having issues:
  1. Defining handle for the image-axis is not allowed by WindowButtonDownFcn.
  2. I can use the handle of the GUI-figure (which is an alternative of the point above), but how do I extract the co-ordinates for later use?
Example code (Matlab)
function draw_lines
% Click the left mouse button to define a point
% Drag the mouse to draw a line to the next point and
% left click again
% Right click the mouse to stop drawing
%
figure('WindowButtonDownFcn',@wbdcb)
ah = axes('DrawMode','fast');
axis ([1 10 1 10])
function wbdcb(src,evnt)
if strcmp(get(src,'SelectionType'),'normal')
[x,y,str] = disp_point(ah);
hl = line('XData',x,'YData',y,'Marker','.');
text(x,y,str,'VerticalAlignment','bottom');drawnow
set(src,'WindowButtonMotionFcn',@wbmcb)
elseif strcmp(get(src,'SelectionType'),'alt')
set(src,'WindowButtonMotionFcn','')
[x,y,str] = disp_point(ah);
text(x,y,str,'VerticalAlignment','bottom');drawnow
end
function wbmcb(src,evnt)
[xn,yn,str] = disp_point(ah);
xdat = [x,xn];
ydat = [y,yn];
set(hl,'XData',xdat,'YData',ydat);
end
end
function [x,y,str] = disp_point(ah)
cp = get(ah,'CurrentPoint');
x = cp(1,1);y = cp(1,2);
str = ['(',num2str(x,'%0.3g'),', ',num2str(y,'%0.3g'),')'];
end
end
  2 件のコメント
Image Analyst
Image Analyst 2016 年 7 月 18 日
Are you using GUIDE? Or are you trying to do it the hard way and define all the properties/settings and callbacks yourself?
And what's in the axes control? If there is something like an image you'll have to set a callback for the image since it lies on top of the axes, or else set the hittest for the image to be off.
ImageProcNaive
ImageProcNaive 2016 年 9 月 3 日
Yes, using GUIDE. Also, there will be an image displayed in the axes. I have to draw a line along an object displayed in the image. I will later measure the length of the line; but it's important to have the visual of a line.

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

回答 (0 件)

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by