getPixelRegionFormatFcn
Get function handle that formats pixel value into character vector
Description
returns a function that formats one or more pixel values in image model
fun
= getPixelRegionFormatFcn(imgmodel
)imgmodel
as character vectors. The format of the character vectors
matches the information displayed in the Pixel
Region tool.
Examples
Get RGB Pixel Values From Image Model
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');
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...'}
Get Multiple Grayscale Pixel Values From Image Model
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 grayscale image.
h = imshow('liftingbody.png');
im = imagemodel(h);
Specify the row and column coordinates of multiple pixels as vectors.
r = [50 400 500]; c = [250 300 500];
Get the numeric value of the pixel using the getPixelValue
function.
pxValue = getPixelValue(im,r,c)
pxValue = 1x3 uint8 row vector
151 74 104
There are two steps to get the pixel region strings for the pixels. First, get a function formatFcn
that formats numeric pixel values by using the getPixelRegionFormatFcn
function. Then, specify the row and column coordinate of the pixels as input arguments to formatFcn
to get the formatted strings.
formatFcn = getPixelRegionFormatFcn(im); pxRegStr = formatFcn(r,c)
pxRegStr = 3x1 cell
{'151'}
{'74' }
{'104'}
Input Arguments
imgmodel
— Image model
scalar imagemodel
object
Image model, specified as a scalar imagemodel
object.
Output Arguments
fun
— Pixel value format function
function handle
Pixel value format function, returned as a function handle. The function
fun
has two input arguments, which are the row and column
coordinates of pixels in the target image. For grayscale, indexed, and binary images,
fun
can accept row vectors specifying multiple pixels. For RGB
images, fun
only accepts a single pixel. fun
returns pixel values as a cell array of character vectors, formatted according to the
input image type.
Image Type | Sample Format of Pixel Value |
---|---|
Grayscale | '000' |
Truecolor (RGB) | 'R:000 G:000 B:000' |
Binary | '0' |
Indexed | '<000> R:0.00 G:0.00 B:0.00' |
Data Types: function_handle
Version History
Introduced before R2006a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)