This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

impixel

Pixel color values

Syntax

P = impixel
P = impixel(I)
P = impixel(X,map)
P = impixel(I,c,r)
P = impixel(X,map,c,r)
P = impixel(x,y,I,xi,yi)
P = impixel(x,y,X,map,xi,yi)
[xi2,yi2,P] = impixel(___)

Description

P = impixel lets you select pixels interactively from the image in the current axes. With this syntax and the other interactive syntaxes, the pixel selection tool blocks the MATLAB® command line until you complete the operation. 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.

P = impixel(I) returns the value of pixels in image I. The impixel function displays the image and waits for you to select pixels in the image using the mouse.

P = impixel(X,map) returns the value of pixels in indexed image X with corresponding colormap, map. The impixel function displays the image and waits for you to select pixels in the image using the mouse.

example

P = impixel(I,c,r) returns the values of specified pixels in image I. The column and row coordinates of the sampled pixels are specified by c and r. The kth row of P contains the RGB values for the pixel (r(k), c(k)).

P = impixel(X,map,c,r) returns the values of specified pixels in indexed image X. The column and row coordinates of the sampled pixels are specified by c and r.

P = impixel(x,y,I,xi,yi) returns the values of pixels in the specified image, I, using a nondefault coordinate system wherex and y specify the image limits. xi and yi specify the spatial coordinates of the pixels whose values are returned in P.

P = impixel(x,y,X,map,xi,yi) returns the values of pixels in the specified indexed image, X, with corresponding colormap, map, using a nondefault coordinate system.

[xi2,yi2,P] = impixel(___) additionally returns the coordinates of the selected pixels.

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

Input image, specified as an RGB, grayscale, or binary image.

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

Indexed image, specified as a numeric array.

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

Colormap associated with the indexed image X, specified as an m-by-3 numeric array. Values with data type single or double must be in the range [0, 1].

Data Types: single | double | uint8

Column or row index of pixels to sample, specified as a vector of positive integers. The length and data type of c and r must match.

Data Types: single | double

Image limits in world coordinates along the x or y direction, specified as a 2-element numeric vector of the form [min max]. The values of x and y set the image XData and YData. The data type of x and y must match.

Data Types: single | double

x- or y-coordinates of pixels to sample, in the world coordinate system defined by x and y, specified as a numeric vector. The length and data type of xi and yi 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, map.
BinaryReturns the intensity value as an RGB triplet, where R=G=B. The values are data type double.

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

  • If you select pixels interactively using the mouse, or if you specify pixels using row and column indices c and r, then xi2 and yi2 are interpreted as pixel indices.

  • If you specify the image limits, x and y, in a nondefault spatial coordinate system, then xi2 and yi2 are interpreted as x- and y-coordinates in that coordinate system.

See Also

|

Introduced before R2006a