If I load and display an image, for example

c = imread('cameraman.tif');

then in the plot window, under the image itself, there are two numbers indicating the current cursor position, in the form

[39.25, 120.6]

I have two questions about this:

  1. Can the display be tweaked so that the positions are integers? So one image pixel per screen pixel?
  2. Can this information include the grayscale/rgb value of the pixel, such as

    [23, 46] = 127


    [23, 46] = (46,128,210)?

I've tried fiddling with the "axis" command, but I haven't found anything which helps.

I guess what I want is something like Matlab's "Pixel Information Tool" impixelinfo: http://www.mathworks.com.au/help/images/ref/impixelinfo.html though I know from the octave image wiki at http://wiki.octave.org/Image_package that impixelinfo is not currently implemented in Octave. But maybe there's another way to achieve the same result?

I'm using Octave-3.8.0, the image package 2.2.0, under linux (Ubuntu 12.04).


GNU Octave 3.8 uses FLTK as standard graphics_toolkit. Unfortunately WindowButtonMotionFcn is only triggered if a button is pressed while the mouse moves (dragging) with this toolkit (Today I would consider this as a bug). But you can use WindowButtonDownFcn.

This examples updates the title with the position and the image value at that position if you click in 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, :));

  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));

set (gcf, 'WindowButtonDownFcn', @btn_down);

You can also place a text next to the cursor if you want.

  • If you want to view pixel values while mouse drag instead of button press use set (gcf, 'WindowButtonMotionFcn', @btn_down) – sriram Jul 6 '17 at 15:57
  • @sriram: You should read my answer which clearly says that WindowButtonMotionFcn doesn't work with Octave 3.8 – Andy Jul 6 '17 at 20:46
  • Agreed. I did not read the version. – sriram Jul 7 '17 at 19:41

Your Answer

