www.gusucode.com > visionhdl 源码程序 matlab案例代码 > visionhdl/LookUpTableSysObjExample.m

    %% Compute Negative Image
% 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.
[pixIn,ctrlIn] = step(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)] = step(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] = step(pix2frm,pixOut,ctrlOut);
if frmValid
    figure
    imshow(frmOutput, 'InitialMagnification',300)
    title 'Output Image'
end