Azzera filtri
Azzera filtri

Customize get points function over an image function

5 visualizzazioni (ultimi 30 giorni)
Gabriel
Gabriel il 10 Giu 2016
Risposto: Geoff Hayes il 13 Giu 2016
Dear all,
I ned to create a GUI wich shows an image and the user must be able to perform the following:
1 - Select several points using the mouse;
2 - When the user is done, hit "RETURN"*;
3 - After hiting "RETURN", IF the user wants to edit the one of the points, he/she must click over the desired point and drag it to where he/she wants.
I created this function:
function [x, y] = test(img)
[lin, col] = size(img);
fig = figure('WindowButtonDownFcn', {@func, lin, col}, 'KeyPressFcn', @keyfunc);
imshow(img, []);
% axs = axes('position', [1 col 1 lin]);
set(gca, 'Ydir', 'reverse');
x = [];
y = [];
uiwait(fig);
function func(src, callback, lin, col)
seltype = get(fig, 'SelectionType');
set(gca, 'Ydir', 'reverse');
if strcmp(seltype, 'normal')
set(fig, 'Pointer', 'circle');
cp = get(fig, 'CurrentPoint');
xinit = cp(1, 1);
yinit = cp(1, 2);
x = [x, xinit];
y = [y, yinit];
hl = line('XData', xinit, 'YData', yinit, 'color', 'b', 'Marker', '.');
set(fig, 'WindowButtonMotionFcn', {@moveMouse, lin, col});
set(fig, 'WindowButtonUpFcn', @mouseRelease);
end
function moveMouse(src, callback, lin, col)
cp = get(fig, 'CurrentPoint');
xdata = [xinit, cp(1, 1)];
ydata = [yinit, cp(1, 2)];
set(hl, 'XData', xdata);
set(hl, 'YData', ydata);
drawnow;
end
function mouseRelease(src, callback)
last_selection = get(fig, 'SelectionType');
if strcmp(last_selection, 'alt')
set(fig, 'Pointer', 'arrow');
set(fig, 'WindowButtonMotionFcn','');
set(fig, 'WindowButtonUpFcn','');
else
return;
end
end
end
function keyfunc(src, callback)
keypressed = get(fig, 'CurrentCharacter');
if keypressed == 13
uiresume(fig);
end
end
end
Q1 - It can plot the image but the coordinate system has its zero at the top-left edge of the figure. How can I move it to the left-top of the image?
Q2 - How can I implement the item number 3 (IF the user wants to edit the one of the points, he/she must click over the desired point and drag it to where he/she wants)?
Thank you all in advance,

Risposte (1)

Geoff Hayes
Geoff Hayes il 13 Giu 2016
Gabriel - see the answer to your question http://www.mathworks.com/matlabcentral/answers/286840-how-can-i-edit-the-coordinate-of-a-point-ploted-on-an-image which should contain enough information for you to register mouse events against the axes as opposed to the figure, and how to drag and drop a pixel from one location to another.

Categorie

Scopri di più su Interactive Control and Callbacks in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by