Main Content

getPixelInfoString

Get pixel value as character vector

Description

pixval = getPixelInfoString(imgmodel,r,c) returns as a character vector the value of a single pixel with (row, column) coordinate (r, c) in image imgmodel. The format of the character vector matches the information displayed in the Pixel Information tool.

example

Examples

collapse all

Pixel values obtained from an imagemodel object can be returned in several formats suitable for display in different interactive image processing tools.

Create an image model associated with a color image.

h = imshow('flamingos.jpg');

Figure contains an axes object. The hidden axes object contains an object of type image.

im = imagemodel(h)
 
im =
 
IMAGEMODEL object accessing an image with these properties:

       ClassType: 'uint8'
    DisplayRange: []
     ImageHeight: 972
       ImageType: 'truecolor'
      ImageWidth: 1296
    MinIntensity: []
    MaxIntensity: []

 

Select a pixel by specifying row and column coordinates. This pixel has (row, column) coordinates (100, 200).

r = 100;
c = 200;

Get the numeric value of the pixel using the getPixelValue function.

pxValue = getPixelValue(im,r,c)
pxValue = 1x3 uint8 row vector

   104    95    54

Get the default pixel information string using the getDefaultPixelInfoString function. This string depends on the type of image but does not use the pixel values. The pixel information string is suitable for use with the Pixel Information tool.

defaultPxInfoStr = getDefaultPixelInfoString(im)
defaultPxInfoStr = 
'[R G B]'

Using the same string format, get the pixel information string for the specified pixel by using the getPixelInfoString function.

pxInfoStr = getPixelInfoString(im,r,c)
pxInfoStr = 
'[104 95 54]'

Get the default pixel region string using the getDefaultPixelRegionString function. This string depends on the type of image but does not use the pixel values. The pixel region string is suitable for use with the Pixel Region tool.

defaultPxRegStr = getDefaultPixelRegionString(im)
defaultPxRegStr = 
    'R:000
     G:000
     B:000'

There are two steps to get the pixel region string for the specified pixel in the same string format. First, get a function formatFcn that formats numeric pixel values by using the getPixelRegionFormatFcn function. Then, specify the row and column coordinate of the pixel as input arguments to formatFcn to get the formatted string.

formatFcn = getPixelRegionFormatFcn(im);
pxRegStr = formatFcn(r,c)
pxRegStr = 1x1 cell array
    {'R:104...'}

Input Arguments

collapse all

Image model, specified as a scalar imagemodel object.

Row coordinate of pixel, specified as a positive integer.

Column coordinate of pixel, specified as a positive integer.

Output Arguments

collapse all

Pixel value, returned as a character vector. The table shows the character vector returned for a black pixel for each image type.

Image TypeSample Pixel Value
Grayscale'000'
Truecolor (RGB)'[0 0 0]'
Binary'0'
Indexed'<000> [0 0 0]'

Data Types: char

Version History

Introduced before R2006a