www.gusucode.com > visionhdl工具箱matlab源码程序 > visionhdl/visionhdlexamples/PixelStreamingDesignHDLExample.m
%% Pixel-Streaming Design in MATLAB % This example demonstrates a workflow for designing pixel-stream video % processing algorithms using Vision HDL Toolbox(TM) in the MATLAB(R) % environment and generating HDL code from the design. % % This workflow tests the design using a small thumbnail image to reduce % simulation time. To simulate larger images, such as 1080p video format, % use MATLAB Coder(TM) to accelerate the simulation. See % <matlab:showdemo('DesignAccelerationHDLExample') Accelerate a Pixel-Streaming Design Using MATLAB Coder>. %% Test Bench % In the test bench % <matlab:edit(fullfile(matlabroot,'toolbox','visionhdl','visionhdlexamples','PixelStreamingDesignHDLTestBench.m')) PixelStreamingDesignHDLTestBench>, % the *videoIn* object reads each frame from a video source, and the % *scaler* object reduces this frame from 240p to a thumbnail size for the % sake of simulation speed. This thumbnail image is passed to the *frm2pix* % object, which converts the full image frame to a stream of pixels and % control structures. The function % <matlab:edit(fullfile(matlabroot,'toolbox','visionhdl','visionhdlexamples','PixelStreamingDesignHDLDesign.m')) PixelStreamingDesignHDLDesign> % is then called to process one pixel (and its associated control % structure) at a time. After we process the entire pixel-stream and % collect the output stream, the *pix2frm* object converts the output % stream to full-frame video. The *viewer* object displays the output and % original images side-by-side. % % The workflow above is implemented in the following lines of % <matlab:edit(fullfile(matlabroot,'toolbox','visionhdl','visionhdlexamples','PixelStreamingDesignHDLTestBench.m')) PixelStreamingDesignHDLTestBench>. % % ... % for f = 1:numFrm % frmFull = step(videoIn); % Get a new frame % frmIn = step(scaler,frmFull); % Reduce the frame size % % [pixInVec,ctrlInVec] = step(frm2pix,frmIn); % for p = 1:numPixPerFrm % [pixOutVec(p),ctrlOutVec(p)] = PixelStreamingDesignHDLDesign(pixInVec(p),ctrlInVec(p)); % end % frmOut = step(pix2frm,pixOutVec,ctrlOutVec); % % step(viewer,[frmIn frmOut]); % end % ... % % Both *frm2pix* and *pix2frm* are used to convert between full-frame and % pixel-stream domains. The inner for-loop performs pixel-stream % processing. The rest of the test bench performs full-frame processing % (i.e., *videoIn*, *scaler*, and *viewer*). % % Before the test bench terminates, frame rate is displayed to % illustrate the simulation speed. %% Pixel-Stream Design % The function % <matlab:edit(fullfile(matlabroot,'toolbox','visionhdl','visionhdlexamples','PixelStreamingDesignHDLDesign.m')) PixelStreamingDesignHDLDesign> % accepts a pixel stream and five control signals, and returns a modified % pixel stream and control signals. For more information on the streaming % pixel protocol used by System objects from the Vision HDL Toolbox, see % the % <matlab:helpview(fullfile(docroot,'visionhdl','ug','streaming-pixel-interface.html')) documentation>. % % In this example, the function contains the Gamma Corrector System object. % % The focus of this example is the workflow, not the algorithm design % itself. Therefore, the design code is quite simple. Once you are familiar % with the workflow, it is straightforward to implement advanced video % algorithms by taking advantage of the functionality provided by the % System objects from Vision HDL Toolbox. %% Simulate the Design % Simulate the design with the test bench prior to HDL code generation to make % sure there are no runtime errors. PixelStreamingDesignHDLTestBench; %% % % <<visionhdlgamma_ml_viewer.png>> % % The *viewer* displays the original video on the left, and the output on % the right. One can clearly see that the gamma operation results in a % brighter image. %% HDL Code Generation % To generate HDL code, the relevant files must % be in a writable directory. Execute the following lines of code to copy % the files into a temporary folder. currDir = pwd; tempDir = tempname; % Create a temporary folder and copy the MATLAB files. mkdir(tempDir); demoDir = fullfile(matlabroot,'toolbox','visionhdl','visionhdlexamples'); copyfile(fullfile(demoDir,'PixelStreamingDesignHDLDesign.m'),tempDir); copyfile(fullfile(demoDir,'PixelStreamingDesignHDLTestBench.m'),tempDir); cd(tempDir); %% % Enter the following command to create a new HDL Coder(TM) project, % % coder -hdlcoder -new PixelStreamingDesignProject % % Then, add the file 'PixelStreamingDesignHDLDesign.m' to the project as the MATLAB % Function and 'PixelStreamingDesignHDLTestBench.m' as the MATLAB Test Bench. % % Refer to % <matlab:helpview(fullfile(docroot,'hdlcoder','examples','getting-started-with-matlab-to-hdl-workflow.html')) Getting Started with MATLAB to HDL Workflow> % for a tutorial on creating and populating MATLAB HDL Coder projects. % % Launch the Workflow Advisor. In the Workflow Advisor, right-click the % 'Code Generation' step. Choose the option 'Run to selected task' to % run all the steps from the beginning through HDL code generation. % % Examine the generated HDL code by clicking the links in the log window. % % Run the following commands to clean up the temporary project folder. clear mex; cd(currDir); rmdir(tempDir,'s'); clear currDir tempDir demoDir; %% % Copyright 2014 The MathWorks, Inc. displayEndOfDemoMessage(mfilename)