Main Content

impixel

Pixel color values

Description

Select Pixels Interactively

P = impixel lets you select pixels interactively from the image in the current axes. When you finish selecting pixels, impixel returns the pixel values in p.

Use normal button clicks to select pixels. Press Backspace or Delete to remove the previously selected pixel. To add a final pixel and finish pixel selection in one step, press shift-click, or right-click or double-click. To finish selecting pixels without adding a final pixel, press Return. With this syntax and the other interactive syntaxes, the pixel selection tool blocks the MATLAB® command line until you complete the operation.

P = impixel(I) displays the grayscale, RGB, or binary image I in a figure window and waits for you to select pixels in the image using the mouse.

P = impixel(X,cmap) displays the indexed image X with colormap cmap in a figure window and waits for you to select pixels in the image using the mouse.

Select Pixels by Specifying Coordinates

P = impixel(I,xi,yi) returns the values of pixels in grayscale, truecolor, or binary image I. The pixels have (x, y) coordinates xi and yi.

example

P = impixel(X,cmap,xi,yi) returns the values of pixels in indexed image X with colormap cmap. The pixels have (x, y) coordinates xi and yi.

P = impixel(xref,yref,I,xi,yi) returns the values of pixels in image I using the world coordinate system defined by xref and yref. The pixel vertices have (x, y) coordinates xi and yi in this coordinate system.

P = impixel(xref,yref,X,cmap,xi,yi) returns the values of pixels in the indexed image X with colormap cmap, using the world coordinate system defined by xref and yref. The pixel vertices have (x, y) coordinates xi and yi in this coordinate system.

Additionally Return Selected Pixel Coordinates

[xi2,yi2,P] = impixel(___) additionally returns the (x, y) coordinates of the selected pixels, xi2 and yi2. You can use the input arguments of any other syntax.

Examples

collapse all

Read a truecolor image into the workspace.

RGB = imread('peppers.png');

Determine the column c and row r indices of the pixels to extract.

c = [1 12 146 410];
r = [1 104 156 129];

Return the data at the selected pixel locations.

pixels = impixel(RGB,c,r)
pixels = 4×3

    62    29    64
    62    34    63
   166    54    60
    59    28    47

Input Arguments

collapse all

Image, specified as one of the following.

  • m-by-n numeric matrix representing a grayscale image

  • m-by-n-by-3 numeric array representing a truecolor image

  • m-by-n logical matrix representing a binary mask.

Data Types: single | double | int16 | uint8 | uint16 | logical

Indexed image, specified as a matrix of integers.

Data Types: single | double | uint8 | uint16 | logical

Colormap associated with the indexed image X, specified as a c-by-3 numeric matrix. Each row is a three-element RGB triplet that specifies the red, green, and blue components of a single color of the colormap. Values with data type single or double must be in the range [0, 1].

Data Types: single | double | uint8

x-coordinate of pixels to sample, specified as a numeric vector of the same length and data type as yi. If you specify image limits in a world coordinate system using xref, then xi is in this coordinate system. Otherwise, xi is in the default spatial coordinate system.

Data Types: single | double

y-coordinate of pixels to sample, specified as a numeric vector of the same length and data type as xi. If you specify image limits in a world coordinate system using yref, then yi is in this coordinate system. Otherwise, yi is in the default spatial coordinate system.

Data Types: single | double

Image limits in world coordinates along the x-dimension, specified as a 2-element numeric vector of the form [xmin xmax]. The value of xref sets the image XData. The data type of xref and yref must match.

Data Types: single | double

Image limits in world coordinates along the y-dimension, specified as a 2-element numeric vector of the form [ymin ymax]. The value of yref sets the image YData. The data type of xref and yref must match.

Data Types: single | double

Output Arguments

collapse all

Sampled pixel values, returned as a p-by-3 matrix. impixel always returns pixel values as RGB triplets, regardless of the image type. The values in each row of the matrix depends on the image type.

Image Type

Result

RGBReturns the actual RGB data for the pixel. The values are data type double.
GrayscaleReturns the intensity value as an RGB triplet, where R=G=B. The values are data type double.
IndexedReturns the RGB triplet stored in the row of the colormap that the pixel value points to. The values have the same data type as the colormap, cmap.
BinaryReturns the intensity value as an RGB triplet, where R=G=B. The values are data type double.

x-coordinates of sampled pixels, returned as a numeric vector.

  • If you select pixels interactively using the mouse, then xi2 is interpreted as column indices.

  • If you specify pixel coordinates to sample when you call impixel, then xi2 is interpreted as x-coordinates in the same coordinate system as xi.

y-coordinates of sampled pixels, returned as a numeric vector.

  • If you select pixels interactively using the mouse, then yi2 is interpreted as row indices.

  • If you specify pixel coordinates to sample when you call impixel, then yi2 is interpreted as y-coordinates in the same coordinate system as yi.

Version History

Introduced before R2006a