Getting no results from a mouse click when using ButtonDownFcn with imshow
Afficher commentaires plus anciens
I'm unable to obtain (x,y) coordinates of an image using a mouse click with "imshow". I can do it with "image" but not with "imshow", and I need "imshow". I've seen lots of other posts on this issue, but none of their solutions seem to work, or the discussion is too technical for me.
I have 4 images arranged two by two, and I'm interested in clicking only on the image in subplot (2,2,3). But when I click nothing happens. Apparantly my function "clicky4" is not being called. Here's the relevant section of code:
global x y
.........
Image = single(rgb2gray(FilterRGBImage));
subplot(2, 2, 3);
vv = imshow(Image,'InitialMagnification', 'Fit');
set(vv, 'HitTest','off','PickableParts','none');
% Try to use the mouse to select a pixel
set(gca,'ButtonDownFcn', @clicky4)
And here is my function "clicky4":
function clicky4(gcbo,eventdata,handles)
%This function is supposed to grab the position (x,y) of the mouse upon a click
global x y
v = get(gca,'Currentpoint');
hold on
x = v(1,1);
y = v(1,2);
end
Any suggestions will be much appreciated. I'm a relative beginner at this stuff....
Réponses (1)
Image Analyst
le 16 Mar 2019
1 vote
Would ginput(1) or impixelinfo help you?
8 commentaires
jack feinberg
le 16 Mar 2019
Modifié(e) : jack feinberg
le 16 Mar 2019
Walter Roberson
le 16 Mar 2019
Try using image() instead of imshow() as imshow() tends to clear the axes.
jack feinberg
le 16 Mar 2019
Walter Roberson
le 16 Mar 2019
colormap(gray) after you image()
Are you wanting initial magnification to be 'fit' because your array is larger or smaller than the axes area?
jack feinberg
le 16 Mar 2019
Walter Roberson
le 16 Mar 2019
Is clicky4 stored in the same .m file as the other code, or in a separate clicky4.m file? Is it possibly defined as a nested function?
jack feinberg
le 17 Mar 2019
Jan
le 19 Mar 2019
@jack feinberg: Please use flags only to inform admins and editors about contents, which might conflict with the terms of use, but not to post a comment. Thanks.
Catégories
En savoir plus sur Interactive Control and Callbacks dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!