www.gusucode.com > visionhdl 源码程序 matlab案例代码 > visionhdl/ImageFilterSysObjExample.m
%% Filter a Pixel-Stream % This example implements a 2-D blur filter on a thumbnail image. % Copyright 2015 The MathWorks, Inc. % Set dimensions of the test image frmActivePixels = 64; frmActiveLines = 48; % Load image source frmOrig = imread('rice.png'); % Select a portion of the image matching the desired test size frmInput = frmOrig(1:frmActiveLines,1:frmActivePixels); figure imshow(frmInput,'InitialMagnification',300) title 'Input Image' % Create serializer 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 filter object filt2d = visionhdl.ImageFilter(... 'Coefficients',ones(2,2)/4,... 'CoefficientsDataType','Custom',... 'CustomCoefficientsDataType',numerictype(0,1,2),... 'PaddingMethod','Symmetric'); % 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 to process pixels [~,~,numPixelsPerFrame] = getparamfromfrm2pix(frm2pix); pixOut = zeros(numPixelsPerFrame,1,'uint8'); ctrlOut = repmat(pixelcontrolstruct,numPixelsPerFrame,1); % For each pixel in the padded frame, compute the filtered value % Monitor the control signals to determine latency of the object % The latency of a filter configuration depends on: % * the number of active pixels in a line % * the size of the filter kernel % * optimization of symmetric or duplicate coefficients foundValIn = false; foundValOut = false; for p = 1:numPixelsPerFrame if (ctrlIn(p).valid && foundValIn==0) foundValIn = p; end [pixOut(p),ctrlOut(p)] = step(filt2d,pixIn(p),ctrlIn(p)); if (ctrlOut(p).valid && foundValOut==0) foundValOut = p; end end sprintf('object latency is %d cycles',foundValOut-foundValIn) % Create deserializer with format matching that of the serializer pix2frm = visionhdl.PixelsToFrame(... 'NumComponents',1,... 'VideoFormat','custom',... 'ActivePixelsPerLine',frmActivePixels,... 'ActiveVideoLines',frmActiveLines); % Convert the pixel stream to an image frame [frmOutput,frmValid] = step(pix2frm,pixOut,ctrlOut); if frmValid figure imshow(frmOutput, 'InitialMagnification',300) title 'Output Image' end