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

modelname = 'LookupTableHDL';
open_system(modelname);
set_param(modelname,'SampleTimeColors','on');
set_param(modelname,'SimulationCommand','Update');
set_param(modelname,'Open','on');
set(allchild(0),'Visible','off');

%%
% For a hardware-compatible design, the model converts the input video to a 
% stream of pixel values. The Frame to Pixels and Pixels to Frame blocks are 
% configured to match the format of the video source. 
%
% The Pixel-Stream Lookup Table subsystem contains a Lookup Table block, 
% configured with inversion data. The input pixel data type is |uint8|, so 
% the negative value is |255 - pixel|, or |linspace(255,0,256)|. The output 
% pixel data type is the same as the data type of the table contents, in 
% this case, |uint8|. 

set_param(modelname,'SampleTimeColors','off');
set_param(modelname,'Open','off');
set_param([modelname '/Pixel-Stream Lookup Table'],'Open','on');

%% 
% To generate and check the HDL code referenced in this example, you must
% have an HDL Coder(TM) license.
%
% To generate the HDL code, use the following command:
%
%   makehdl('LookupTableHDL/Pixel-Stream Lookup Table')
%
% To infer a RAM to implement the lookup table, the |LUTRegisterResetType|
% property is set to none. To access this property, right-click the 
% *Lookup Table* block inside the subsystem, and navigate to 
% *HDL Coder* > *HDL Block Properties*.
%
% To generate a test bench for the generated HDL code, use the following command:
%
%   makehdltb('LookupTableHDL/Pixel-Stream Lookup Table')
%
 
set_param([ modelname '/Pixel-Stream Lookup Table'], 'Open', 'off');
close_system(modelname,0);
close all;

%% 
% Copyright 2012 The MathWorks, Inc.