pixel location on an image using mouse click

13 views (last 30 days)
Jason
Jason on 9 Oct 2015
Commented: Jason on 9 Oct 2015
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
  1 Comment
Jason
Jason on 9 Oct 2015
OK, it seems when you load an image, then this does the scaling automatically.

Sign in to comment.

Answers (0)

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!