Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying pixel values of an image in Octave?

If I load and display an image, for example

c = imread('cameraman.tif');
imshow(c)

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

    or

    [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).

like image 684
Alasdair Avatar asked May 17 '14 02:05

Alasdair


People also ask

How do I find the pixel value of an image?

To view the values of pixels in a specific region of an image displayed in Image Viewer, use the Pixel Region tool. The Pixel Region tool superimposes a rectangle, called the pixel region rectangle, over the image displayed in Image Viewer.

How can I see the pixels of an image in Matlab?

To determine the values of one or more pixels in an image and return the values in a variable, use the impixel function. You can specify the pixels by passing their coordinates as input arguments or you can select the pixels interactively using a mouse.

How do you find the pixel value of an image RGB?

Retrieving the pixel contents (ARGB values) of an image −Get the pixel value at every point using the getRGB() method. Instantiate the Color object by passing the pixel value as a parameter. Get the Red, Green, Blue values using the getRed(), getGreen() and getBlue() methods respectively.


1 Answers

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, :));
  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 place a text next to the cursor if you want.

like image 137
Andy Avatar answered Sep 19 '22 01:09

Andy