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.

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. The object accepts and returns 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.

Note

Starting in R2016b, instead of using the step method to perform the operation defined by the System object, you can call the object with arguments, as if it were a function. For example, y = step(obj,x) and y = obj(x) perform equivalent operations.

Construction

LUT = visionhdl.LookupTable returns a System object, LUT, that performs a one-to-one mapping between the input pixel and output pixel, according to the lookup table contents.

LUT = visionhdl.LookupTable(tabledata) returns a lookup table System object, LUT, with the table contents set to TABLEDATA.

Input Arguments

tabledata

One-to-one correspondence between input pixels and output pixels, specified as a vector. This argument sets the Table property value.

Output Arguments

LUT

visionhdl.LookupTable System object

Properties

Table

Map between input pixel values and output pixel values.

  • The table data is a vector, row or column, of any data type. The data type of the table data determines that of pixelOut. See step method.

  • The length of the table data must equal 2WordLength, where WordLength is the size, in bits, of pixelIn. See step method.

  • 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, input value 0.5 maps to the second element, 1 maps to the third, and so on.

Default: uint8(0:1:255)

Methods

stepMap input pixel to output pixel based on table contents
Common to All System Objects
release

Allow System object property value changes

Examples

collapse all

This example creates the negative of an image by looking up the opposite pixel values in a table.

Set dimensions of 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 is uint8 type, 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.

Note: This syntax runs only in R2016b or later. If you are using an earlier release, replace each call of an object with the equivalent step syntax. For example, replace myObject(x) with step(myObject,x).

[pixIn,ctrlIn] = frm2pix(frmInput);

Prepare variables to process pixels. Then, for each pixel in the padded frame, look up the 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

This object implements the algorithms described on the Lookup Table block reference page.

Introduced in R2015a