pixel location on an image using mouse click
13 views (last 30 days)
Show older comments
I am wanting to use the mouse so that when I click the mouse button, it displays a small cross hair on an image (which is on an axes component). I then use the to perform a line scna of an image using those coordinates. I have tried ginput (but this gives a massive cross hair that covers the entire gui), as well as impixelinfo.
This is my attempt after searching.
Inside the GUI's OpeningFcn or the callback function for a button:
set(gcf, 'WindowButtonDownFcn', @getMousePositionOnImage);
set(src, 'Pointer', 'crosshair'); % Optional
pan off % Panning will interfere with this code
Then have a mouse callback function along the lines of:
function getMousePositionOnImage(src, event)
handles = guidata(src);
cursorPoint = get(handles.axesImage, 'CurrentPoint');
curX = cursorPoint(1,1);
curY = cursorPoint(1,2);
However, this only gives the current position within the axes and not the pixel location.
I assume that I just scale these values by the size of the image?
Thanks Jason
Answers (0)
See Also
Categories
Find more on Graphics Object Properties in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!