Saving mouse click coordinates on image in GUI

63 visualizaciones (últimos 30 días)
Brian
Brian el 29 de En. de 2016
Comentada: Brian el 1 de Feb. de 2016
Hello,
How do I record up to 5 mouse click coordinates ([x,y] relative to the image with (0,0) being in the upper left) on an 512 by 512 image (axes1 of my GUI)? I would like the mouse click locations to be saved in a table, so I can use the values for subsequent calculations.
I found the following script online for saving coordinates, but am not sure how it works and where to put this within the GUI script.
function ImageClickCallback (objectHandle , eventData )
axesHandle = get(objectHandle,'Parent');
coordinates = get(handles.axes1,'CurrentPoint');
coordinates = coordinates(1,1:2);
%// then here you can use coordinates as you want ...
For the data-capturing table, I suppose I should be doing the following, but I am not sure which callback section to place it under (do I have to manually create a "mouseclick" callback?):
tableData = {x1,y1,z1;x2,y2,z2;x3,y3,z3;x4,y4,z4;x5,y5,z5};
set(handles.CoordinateTable,'Data',tableData)
The Z values refer to the slice number (obtainable from the slider location) since I am showing a stack of images. I believe that after updating the handles, I should be able to perform my calculations from there.
Apologies for the novice question, as I am quite new to MATLAB. Thank you so much!

Respuesta aceptada

Walter Roberson
Walter Roberson el 30 de En. de 2016
You have done well to find that information already. The additional information you need is
to allow you to store the various coordinates.
The ImageClickCallback is something that you would configure as a ButtonDownFcn callback on the image.
You could also consider using ginput(5) to get up to 5 coordinates. The biggest difference between that and using a ButtonDownFcn as a callback is that ginput() is an active command that has to be issued by a running function which would wait for the coordinates and then proceed, whereas callback functions are passive, with no function running until the user triggers the action.
  1 comentario
Brian
Brian el 1 de Feb. de 2016
I decided to follow the ginput(n) method because it gives a crosshair as well. However, I am unable to get this to work. The crosshair doesn't show on my GUI and it appears no coordinates are saved either. What am I not doing correctly?
% --- Executes on mouse press over axes background.
function axes1_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to axes1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
SliderLocation = round(get(handles.slider1,'Value'));
[xlist ylist]=ginput(5);
tableData = {xlist(1),ylist(1),SliderLocation};
set(handles.CoordinateTable,'Data',tableData)
% Update handles structure
guidata(hObject, handles)
The code is just using the first set of coordinates as example. Thank you so much!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by