Clear Filters
Clear Filters

How can I get the mouse position on an image after uploading it on axes

2 views (last 30 days)
Hi,
I want to display the mouse position on my GUI. The problem is that it works on the axes. But after uploading the image it doesn't work any more. What is the problem? Or is there any other possibility to do it?
% --- 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)
c = get (gca, 'CurrentPoint');
x = c(1,1);
y = c(1,2);
set(handles.xPos, 'string', ['x loc:' num2str(x)]); % update text for x loc
set(handles.yPos, 'string', ['y loc:' num2str(y)]); % update text for y loc

Answers (1)

Guillaume
Guillaume on 20 Dec 2018
By default Image objects capture mouse clicks. So if an Image is displayed in an axes, when you click on it it's the ButtonDownFcn of the Image that gets called, not the axes one.
You can easily turn that off but setting the HitTest property of the Image to off.
%image creation using either imhsow, image, imagesc, whatever...
himage = imshow(something)
himage.HitTest = 'off'; %image won't capture mouse clicks, the axes will instead.
  1 Comment
Ouael Chkoundali
Ouael Chkoundali on 22 Dec 2018
Hi Guillaume,
thanks for your answer. Is there any possibility to show the mouse position without clicking on the axes? It works on a figure but i couldn't do it on axes?

Sign in to comment.

Categories

Find more on Interactive Control and Callbacks 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!