Main Content

visionhdl.LookupTable

Map input pixel to output pixel using custom rule

Description

The visionhdl.LookupTable System object™ uses a custom one-to-one map to convert between an input pixel value and an output pixel value.

To map an input pixel value to an output pixel value:

  1. Create the visionhdl.LookupTable object and set its properties.

  2. Call the object with arguments, as if it were a function.

To learn more about how System objects work, see What Are System Objects?.

Creation

Syntax

LUT = visionhdl.LookupTable(tabledata)

Description

LUT = visionhdl.LookupTable(tabledata) returns a lookup table System object that performs a one-to-one mapping between an input pixel and an output pixel. The mapping is defined by the Table property, which is set to the value of tabledata.

Properties

expand all

Unless otherwise indicated, properties are nontunable, which means you cannot change their values after calling the object. Objects lock when you call them, and the release function unlocks them.

If a property is tunable, you can change its value at any time.

For more information on changing property values, see System Design in MATLAB Using System Objects.

Map between input pixel and output pixel, specified as a row or column vector of any data type. The data type of the table data determines that of pixelOut. This mapping determines the one-to-one correspondence between the input pixelIn value and the output pixelOut value.

  • The length of the table data must equal 2WordLength, where WordLength is the size, in bits, of pixelIn. This object does not perform interpolation. Every input value must have a corresponding output value in the table.

  • The smallest representable value of the input data type maps to the first element of the table, the second smallest value maps to the second element, and so on. For example, if pixelIn has a data type of fixdt(0,3,1), the input value 0 maps to the first element of the table, 0.5 maps to the second element, 1 maps to the third element, and so on.

Example: uint8(linspace(255,0,256))

Usage

Syntax

[pixelOut,ctrlOut] = LUT(pixelIn,ctrlIn)

Description

[pixelOut,ctrlOut] = LUT(pixelIn,ctrlIn) returns the pixel value, pixelOut, located in the table at the address specified by the input pixel value, pixelIn. The object delays the input control signals, ctrlIn, to align the output control signals, ctrlOut, with the output data.

This object uses a streaming pixel interface with a structure for frame control signals. This interface enables the object to operate independently of image size and format, and to connect with other Vision HDL Toolbox™ objects. The object accepts and returns a scalar pixel value and control signals as a structure containing five signals. The control signals indicate the validity of each pixel and its location in the frame. To convert a pixel matrix into a pixel stream and control signals, use the visionhdl.FrameToPixels object. For a full description of the interface, see Streaming Pixel Interface.

Input Arguments

expand all

Input pixel, specified as a scalar intensity value or a row vector of three values representing one pixel in R'G'B' or Y'CbCr color space. For unsigned fixed-point data types, the input word length must be less than or equal to 16.

You can simulate System objects with a multipixel streaming interface, but System objects are not supported for HDL code generation. Use the equivalent blocks to generate HDL code for multipixel algorithms.

Data Types: logical | uint8 | uint16 | fi

Control signals accompanying input pixel stream, specified as a pixelcontrol structure containing five logical data type signals. The signals describe the validity of the pixel and its location in the frame. For more details, see Pixel Control Structure.

Data Types: struct

Output Arguments

expand all

Output pixel, returned as a scalar intensity value or a vector of three values representing R'G'B' or Y'CbCr color space. The data type of the output is the same as the data type of the entries you specify in the Table property.

Control signals accompanying output the pixel stream, returned as a pixelcontrol structure containing five logical data type signals. The signals describe the validity of the pixel and its location in the frame. For more details, see Pixel Control Structure.

Data Types: struct

Object Functions

To use an object function, specify the System object as the first input argument. For example, to release system resources of a System object named obj, use this syntax:

release(obj)

expand all

stepRun System object algorithm
releaseRelease resources and allow changes to System object property values and input characteristics
resetReset internal states of System object

Examples

collapse all

Create the negative of an image by looking up the opposite pixel values in a table.

Set dimensions of the test image, and load an image source. Select a portion of the image matching the desired test size.

frmActivePixels = 64;
frmActiveLines = 48;
frmOrig = imread('rice.png');
frmInput = frmOrig(1:frmActiveLines,1:frmActivePixels);
figure
imshow(frmInput,'InitialMagnification',300)
title 'Input Image'

Create a serializer object and define inactive pixel regions.

frm2pix = visionhdl.FrameToPixels( ...
      'NumComponents',1, ...
      'VideoFormat','custom', ...
      'ActivePixelsPerLine',frmActivePixels, ...
      'ActiveVideoLines',frmActiveLines, ...
      'TotalPixelsPerLine',frmActivePixels+10, ...
      'TotalVideoLines',frmActiveLines+10, ...
      'StartingActiveLine',6, ...     
      'FrontPorch',5);

Create a lookup table object. The input pixel data type is uint8, so the negative value is 255-pixel. The output pixel data type is the same as the data type of the table contents.

tabledata = uint8(linspace(255,0,256));
inverter = visionhdl.LookupTable(tabledata);

Serialize the test image. pixIn is a vector of intensity values. ctrlIn is a vector of control signal structures.

[pixIn,ctrlIn] = frm2pix(frmInput);

Initialize the output variables. Then, for each pixel in the padded frame, look up its negative value.

[~,~,numPixelsPerFrame] = getparamfromfrm2pix(frm2pix);
pixOut = zeros(numPixelsPerFrame,1,'uint8');
ctrlOut  = repmat(pixelcontrolstruct,numPixelsPerFrame,1);
for p = 1:numPixelsPerFrame  
    [pixOut(p),ctrlOut(p)] = inverter(pixIn(p),ctrlIn(p));
end

Create deserializer object with a video format matching that of the serializer. Convert the output pixel stream to an image frame, and display the result.

pix2frm = visionhdl.PixelsToFrame( ...
      'NumComponents',1, ...
      'VideoFormat','custom', ...
      'ActivePixelsPerLine',frmActivePixels, ...
      'ActiveVideoLines',frmActiveLines);
[frmOutput,frmValid] = pix2frm(pixOut,ctrlOut);
if frmValid
    figure
    imshow(frmOutput,'InitialMagnification',300)
    title 'Output Image'
end

Algorithms

expand all

Introduced in R2015a