www.gusucode.com > visionhdl工具箱matlab源码程序 > visionhdl/visionhdl/+visionhdl/en/Histogram.m
classdef Histogram< matlab.System & matlab.system.mixin.Propagates & matlab.system.mixin.CustomIcon & matlab.system.mixin.Nondirect %Histogram Generates a histogram of the elements in the input image. % histo = visionhdl.Histogram returns a System object, histo, that % computes two-dimensional histogram of an input stream based on the % input control signals. % % histo = visionhdl.Histogram('PropertyName',PropertyValue,...) % returns a histogram System object, histo, with each specified % property set to the specified value. % % histo = visionhdl.Histogram(Bins,'PropertyName',PropertyValue,...) % returns a histogram System object, histo, with the NumBins property % set to Bins, other specified properties set to the specified values. % % Step method syntax: % [dataOut,readReady,validOut] = step(histo,pixIn,ctrlIn,binAddr,binReset) % returns a histogram value based on input data and control signals. % % The input pixIn is a scalar image pixel and the data type can be % double/single, unsigned integer, or Boolean. The input data binAddr % indicates the bin number for reading out histogram value when output % readReady is high. It is a scalar unsigned interger and the word % length is determined by NumBins. The output dataOut is a scalar % histogram value and the data type is an unsigned integer. % % ctrlIn is a structure consisting of five control signals. See also % <a href="matlab:doc visionhdl.FrameToPixels">visionhdl.FrameToPixels</a> or <a href="matlab:doc pixelcontrolstruct">pixelcontrolstruct</a>. % Input dataIn is contributed to the histogram calculation when % validIn is high. validOut indicates the validity of the computed % histogram value. binReset triggers the memory initialization process % when the value is high. It automatically takes NumBins cycles to % clear the memory contents to zero. All control signals are ignored % during the reset process. The output readReady indicates when the % histogram value is ready for read. % % System objects may be called directly like a function instead of using % the step method. For example, y = step(obj, x) and y = obj(x) are % equivalent. % % Histogram methods: % % step - See above description for use of this method % release - Allow property value and input characteristics changes % clone - Create median filter object with same property values % isLocked - Locked status (logical) % % Histogram properties: % % NumBins - Number of bins in the histogram % OutputDataType - Output Data Type % OutputWL - Word length of Output % % % EXAMPLE: % % Generate the histogram of an image % frm2pix = visionhdl.FrameToPixels(... % 'VideoFormat','custom',... % 'ActivePixelsPerLine',32,... % 'ActiveVideoLines',18,... % 'TotalPixelsPerLine',42,... % 'TotalVideoLines',28,... % 'StartingActiveLine',6,... % 'FrontPorch',5); % [actPixPerLine,actLine,numPixPerFrm] = getparamfromfrm2pix(frm2pix); % % pix2frm = visionhdl.PixelsToFrame(... % 'VideoFormat','custom',... % 'ActivePixelsPerLine',actPixPerLine,... % 'ActiveVideoLines',actLine); % % histo = visionhdl.Histogram(... % 'NumBins','256'); % % frmFull = imread('pout.tif'); % % ctrlDummy = struct('hStart',false,'hEnd',false,'vStart',false,'vEnd',false,'valid',false); % numBins = str2double(histo.NumBins); % numFrm = 2; % for f = 1:numFrm % % Reset % for p = 1:numBins % step(histo,uint8(0),ctrlDummy,uint8(0),true); % end % % % Call the pixel-stream design to generate histogram % frmIn = frmFull(79+f:78+actLine+f,93+f:92+actPixPerLine+f); % [pixInVec,ctrlInVec] = step(frm2pix,frmIn); % for p = 1:numPixPerFrm % [~,readRdy,~] = step(histo,pixInVec(p),ctrlInVec(p),uint8(10),false); % end % % % Read out histogram results % histValVec = zeros(numBins+2,1,'uint16'); % readRdyVec = [readRdy;false(numBins+2,1)]; % validOutVec = false(numBins+2,1); % for p = 1:numBins+2 % (RAM delay+outputReg) % if readRdyVec(p) % [histValVec(p),readRdyVec(p+1),validOutVec(p)] = step(histo,uint8(0),ctrlDummy,uint8(p-1),false); % end % end % % % Call full-frame reference function % histVecRef = imhist(frmIn); % % % Compare the results % if ~isequal(uint16(histVecRef),histValVec(3:end)) % fprintf('frame %d: reference and design output did not match!\n',f); % return; % end % end % % See also imhist. % Copyright 2014-2016 The MathWorks, Inc. methods function out=Histogram %Histogram Generates a histogram of the elements in the input image. % histo = visionhdl.Histogram returns a System object, histo, that % computes two-dimensional histogram of an input stream based on the % input control signals. % % histo = visionhdl.Histogram('PropertyName',PropertyValue,...) % returns a histogram System object, histo, with each specified % property set to the specified value. % % histo = visionhdl.Histogram(Bins,'PropertyName',PropertyValue,...) % returns a histogram System object, histo, with the NumBins property % set to Bins, other specified properties set to the specified values. % % Step method syntax: % [dataOut,readReady,validOut] = step(histo,pixIn,ctrlIn,binAddr,binReset) % returns a histogram value based on input data and control signals. % % The input pixIn is a scalar image pixel and the data type can be % double/single, unsigned integer, or Boolean. The input data binAddr % indicates the bin number for reading out histogram value when output % readReady is high. It is a scalar unsigned interger and the word % length is determined by NumBins. The output dataOut is a scalar % histogram value and the data type is an unsigned integer. % % ctrlIn is a structure consisting of five control signals. See also % <a href="matlab:doc visionhdl.FrameToPixels">visionhdl.FrameToPixels</a> or <a href="matlab:doc pixelcontrolstruct">pixelcontrolstruct</a>. % Input dataIn is contributed to the histogram calculation when % validIn is high. validOut indicates the validity of the computed % histogram value. binReset triggers the memory initialization process % when the value is high. It automatically takes NumBins cycles to % clear the memory contents to zero. All control signals are ignored % during the reset process. The output readReady indicates when the % histogram value is ready for read. % % System objects may be called directly like a function instead of using % the step method. For example, y = step(obj, x) and y = obj(x) are % equivalent. % % Histogram methods: % % step - See above description for use of this method % release - Allow property value and input characteristics changes % clone - Create median filter object with same property values % isLocked - Locked status (logical) % % Histogram properties: % % NumBins - Number of bins in the histogram % OutputDataType - Output Data Type % OutputWL - Word length of Output % % % EXAMPLE: % % Generate the histogram of an image % frm2pix = visionhdl.FrameToPixels(... % 'VideoFormat','custom',... % 'ActivePixelsPerLine',32,... % 'ActiveVideoLines',18,... % 'TotalPixelsPerLine',42,... % 'TotalVideoLines',28,... % 'StartingActiveLine',6,... % 'FrontPorch',5); % [actPixPerLine,actLine,numPixPerFrm] = getparamfromfrm2pix(frm2pix); % % pix2frm = visionhdl.PixelsToFrame(... % 'VideoFormat','custom',... % 'ActivePixelsPerLine',actPixPerLine,... % 'ActiveVideoLines',actLine); % % histo = visionhdl.Histogram(... % 'NumBins','256'); % % frmFull = imread('pout.tif'); % % ctrlDummy = struct('hStart',false,'hEnd',false,'vStart',false,'vEnd',false,'valid',false); % numBins = str2double(histo.NumBins); % numFrm = 2; % for f = 1:numFrm % % Reset % for p = 1:numBins % step(histo,uint8(0),ctrlDummy,uint8(0),true); % end % % % Call the pixel-stream design to generate histogram % frmIn = frmFull(79+f:78+actLine+f,93+f:92+actPixPerLine+f); % [pixInVec,ctrlInVec] = step(frm2pix,frmIn); % for p = 1:numPixPerFrm % [~,readRdy,~] = step(histo,pixInVec(p),ctrlInVec(p),uint8(10),false); % end % % % Read out histogram results % histValVec = zeros(numBins+2,1,'uint16'); % readRdyVec = [readRdy;false(numBins+2,1)]; % validOutVec = false(numBins+2,1); % for p = 1:numBins+2 % (RAM delay+outputReg) % if readRdyVec(p) % [histValVec(p),readRdyVec(p+1),validOutVec(p)] = step(histo,uint8(0),ctrlDummy,uint8(p-1),false); % end % end % % % Call full-frame reference function % histVecRef = imhist(frmIn); % % % Compare the results % if ~isequal(uint16(histVecRef),histValVec(3:end)) % fprintf('frame %d: reference and design output did not match!\n',f); % return; % end % end % % See also imhist. end function computeHist(in) %#ok<MANU> end function dataProcess(in) %#ok<MANU> end function getExecutionSemanticsImpl(in) %#ok<MANU> % works in both classic and synchronous subsystems end function getHeaderImpl(in) %#ok<MANU> %getHeaderImpl Return header for object display end function getIconImpl(in) %#ok<MANU> end function getInputNamesImpl(in) %#ok<MANU> end function getNumInputsImpl(in) %#ok<MANU> end function getNumOutputsImpl(in) %#ok<MANU> end function getOutputDataTypeImpl(in) %#ok<MANU> end function getOutputNamesImpl(in) %#ok<MANU> end function getOutputSizeImpl(in) %#ok<MANU> end function getPropertyGroupsImpl(in) %#ok<MANU> %getPropertyGroupsImpl Return property groups for object display end function histFSM(in) %#ok<MANU> % ********************************************** % {RAMIni, sysReady, dataAcq,readOut} % RAMIni: wake up state, takes Numbins cycle to reset, ignore all control % signals, automatically goes to Ready state when reset is complete % Ready: Goes to DataAcq when vStart ==1, goes to RAMIni when % RAMReset ==1 % DataAcq: stay when vStart ==1; goes to RAMIni when % RAMReset==1; goes to Readout when vEnd ==1 % Readout: goes to DataAcq when vStart ==1 (running % histogram);goes to RAMIni when RAMReset ==1; end function isInactivePropertyImpl(in) %#ok<MANU> % switch prop = '' end function isOutputComplexImpl(in) %#ok<MANU> end function isOutputFixedSizeImpl(in) %#ok<MANU> end function loadObjectImpl(in) %#ok<MANU> end function outputImpl(in) %#ok<MANU> % outputImpl: send output, do not update states end function resetImpl(in) %#ok<MANU> % resetImpl % since the states have already been appropriately sized by % setupImpl, we just need to initialize them end function saveObjectImpl(in) %#ok<MANU> % Save the public properties end function setupImpl(in) %#ok<MANU> end function showSimulateUsingImpl(in) %#ok<MANU> end function startFrameCleanup(in) %#ok<MANU> end function updateImpl(in) %#ok<MANU> % updateImpl: update states, no output end end methods (Abstract) end properties %NumBins Number of bins % Specify the number of bins in the histogram as one of ['32'| % '64'|'128'|'256'|'512'|'1024']. The default value of this % property is '256'. NumBins; %OutputDataType Data type % Specify the data type of the histogram value as one of [ 'double' % | 'single' | 'Unsigned fixed point']. OutputDataType; % OutputWL Word length % Specify the word length of the histogram value as an integer % scalar greater than zero. This property is applicable when the % OutputDataType property is 'Unsigned fixed point'. The default % value of this property is 16. OutputWL; end end