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

    %% Design a Hardware-Targeted Image Filter

%% Import Data
origIm = imread('rice.png');
origImSize = size(origIm)
imActivePixels = 64;
imActiveLines = 48;
inputIm = origIm(1:imActiveLines,1:imActivePixels);
figure
imshow(inputIm,'InitialMagnification',300)
title 'Input Image'
%% Serialize Data
frm2pix = visionhdl.FrameToPixels(...
         'NumComponents',1,...
         'VideoFormat','custom',...
         'ActivePixelsPerLine',imActivePixels,...
         'ActiveVideoLines',imActiveLines,...
         'TotalPixelsPerLine',imActivePixels+20,...
         'TotalVideoLines',imActiveLines+10,...
         'StartingActiveLine',6,...     
         'FrontPorch',10);
%%
% Use the <docid:visionhdl_ref.buuame6> function to get useful image dimensions from the serializer object. This syntax discards the first two returned values, and keeps only the total number of pixels in the padded frame.
[~,~,numPixelsPerFrame] = getparamfromfrm2pix(frm2pix);
%%
% Call the object to convert the image into a vector of pixels and a vector
% of control signals. 
%
% *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)|.
[pixel,ctrl] = frm2pix(inputIm);
%%
% Preallocate the output vectors for a more efficient simulation.
pixelOut = zeros(numPixelsPerFrame,1,'uint8');
ctrlOut  = repmat(pixelcontrolstruct,numPixelsPerFrame,1);
%% Design HDL-Compatible Model
%
% <include>HDLTargetedDesign.m</include> 
%
%% Filter the Pixel Stream
% Call the function once for each pixel in the padded frame, which is represented by the |pixel| vector.
 for p = 1:numPixelsPerFrame
    [pixelOut(p),ctrlOut(p)] = HDLTargetedDesign(pixel(p),ctrl(p));
 end
%% Deserialize Filtered Pixel Stream
pix2frm = visionhdl.PixelsToFrame(...
         'NumComponents',1,...
         'VideoFormat','custom',...
         'ActivePixelsPerLine',imActivePixels,...
         'ActiveVideoLines',imActiveLines);
%%
% Call the object to convert the output of the HDL-targeted function to a matrix.
[outputIm,validIm] = pix2frm(pixelOut,ctrlOut);
%% Display Results
% Use the |imshow| function to display the result of the operation.
if validIm
    figure
    imshow(outputIm,'InitialMagnification',300)
    title 'Output Image'
end