www.gusucode.com > images 案例代码 matlab源码程序 > images/ImageSharpeningHDLTestBench.m
function ImageSharpeningHDLTestBench % ImageSharpeningHDLTestBench Compare the image output from full-frame video % reference design and pixel-stream design, and provide test bench % for HDL code generation % Copyright 2015 The MathWorks, Inc. imgBlur = imread('riceblurred.png'); sharpCoeff = [0 0 0;0 1 0;0 0 0]-fspecial('laplacian',0.2); imgSharp = imfilter(imgBlur,sharpCoeff,'symmetric'); % frm2pix converts an input frame to a stream of pixels and control structures frm2pix = visionhdl.FrameToPixels(... 'VideoFormat','Custom',... 'ActivePixelsPerLine',256,... 'ActiveVideoLines',256,... 'TotalPixelsPerLine',256+10,... 'TotalVideoLines',256+10,... 'StartingActiveLine',3,... 'FrontPorch',5); [actPixPerLine,actLine,numPixPerFrm] = getparamfromfrm2pix(frm2pix); % pix2frm converts a pixel stream and control structures to a full frame pix2frm = visionhdl.PixelsToFrame(... 'VideoFormat','Custom',... 'ActivePixelsPerLine',actPixPerLine,... 'ActiveVideoLines',actLine); pixOutVec = zeros(numPixPerFrm,1,'uint8'); ctrlOutVec = repmat(pixelcontrolstruct,numPixPerFrm,1); tic; [pixInVec,ctrlInVec] = step(frm2pix,imgBlur); for p = 1:numPixPerFrm [pixOutVec(p),ctrlOutVec(p)] = ImageSharpeningHDLDesign(pixInVec(p),ctrlInVec(p)); end imgOut = step(pix2frm,pixOutVec,ctrlOutVec); t = toc; % Compare the result imgDiff = imabsdiff(imgSharp,imgOut); fprintf('The maximum difference between corresponding pixels is %d.\n',max(imgDiff(:))); fprintf('A total of %d pixels are different.\n',nnz(imgDiff)); fprintf('\nSimulation took %f seconds to finish.\n',t);