GNU Octave 3.8 uses FLTK as standard toolkit graphics. Unfortunately, WindowButtonMotionFcn is launched only if the button is pressed when the mouse moves (drags) using this toolkit (today I would consider this as an error). But you can use WindowButtonDownFcn.
In this example, you are updating the title with the position and value of the image at that position if you click on the image:
img = imread ("cameraman.png"); imshow (img) function btn_down (obj, evt) cp = get (gca, 'CurrentPoint'); x = round (cp(1, 1)); y = round (cp(1, 2)); img = get (findobj (gca, "type", "image"), "cdata"); img_v = NA; if (x > 0 && y > 0 && x <= columns (img) && y <= rows (img)) img_v = squeeze (img(y, x, :)); endif if (numel (img_v) == 3) # rgb image title(gca, sprintf ("(%i, %i) = %i, %i, %i", x, y, img_v(1), img_v(2), img_v(3))); elseif (numel (img_v) == 1) # gray image title(gca, sprintf ("(%i, %i) = %i", x, y, img_v)); endif endfunction set (gcf, 'WindowButtonDownFcn', @btn_down);
You can also put text next to the cursor if you wish.
Andy
source share