www.gusucode.com > visionhdl工具箱matlab源码程序 > visionhdl/visionhdl/+visionhdl/en/DemosaicInterpolator.m

    classdef DemosaicInterpolator< matlab.system.mixin.CustomIcon & matlab.system.mixin.Propagates & visionhdl.internal.abstractLineMemoryKernel & matlab.system.mixin.Nondirect
%DemosaicInterpolator Performs Demosaicing of an input image in Bayer
%  format with the specified alignment. The alignment is identified as
%  the sequence of R, G and B pixels for the top left 2x2 neighborhood of the input image.
%
%  demosaicInterpolate = visionhdl.DemosaicInterpolator returns a System object, demosaicInterpolate,
%  that performs demosaicing of a Bayer pattern encoded input stream,
%  based on the input control signals.
%
%  demosaicInterpolate = visionhdl.DemosaicInterpolator('PropertyName',PropertyValue,...)
%  returns a HDL Demosaic System object demosaicInterpolate, with each specified
%  property set to the specified value.
%
%  When Bilinear Interpolation is selected, the interpolated pixel is found
%  simply by averaging a neighborhood of 3x3 pixels. When Gradient-Corrected
%  Bilinear Interpolation is selected, the interpolated pixel is found
%  through a process of averaging, and applying a correction based on the
%  local gradient of a 5x5 neighborhood. This has a higher complexity,
%  however achieves a higher PSNR than Bilinear Interpolation.
%
%  Step method syntax: 
%  [pixOut,ctrlOut] = step(demosaicInterpolate,pixIn,ctrlIn)
%  returns the interpolated R,G,B values based on the input data
%  and input control signals.
%
%  The input pixIn is a scalar image pixel and the data type can be
%  double/single, unsigned integer, or fixed point. The 
%  data type of output pixOut follows that of pixIn. Signed data
%  types are not supported for simulation or HDL code generation. 
%  ctrlIn and ctrlOut are structures consisting of five 
%  control signals. See also <a href="matlab:doc visionhdl.FrameToPixels">visionhdl.FrameToPixels</a> or <a href="matlab:doc pixelcontrolstruct">pixelcontrolstruct</a>.   
%
%  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.
%
%  DemosaicInterpolator methods:
%
%   step     - See above description for use of this method
%   release  - Allow property value and input characteristics changes
%   clone    - Create demosaicInterpolate object with same property values
%   isLocked - Locked status (logical)
%
%  DemosaicInterpolator properties: -
%
%   Algorithm     - Choose algorithm used to perform interpolation.
%   SensorAlignment - Alignment of the input image.
%   LineBufferSize   - Size of line buffer memory, equivalent to largest row.
%
%  % EXAMPLE:
% % Form an [R G B] output image from a Bayer format input.
% % Set the dimensions of the test image
% frmActivePixels = 256;
% frmActiveLines = 192;
% 
% % Load the source image
% % This image is in Bayer pattern: each pixel is represented by one value,
% % alternating green values with red and blue values.
% frmOrig = imread('mandi.tif');
% figure
% imshow(frmOrig,'InitialMagnification',20)
% title 'Full Image (Scaled Down)'
% 
% % Select a portion of the image matching the desired test size.
% % These offsets select the face of the woman in the image.
% frmInput = frmOrig(900:899+frmActiveLines,2350:2349+frmActivePixels);
% figure
% imshow(frmInput)
% title 'Input Image'
% 
% % Create serializer and specify size of 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 demosaic interpolator
% % Specify the sequence of color values matching the 2-by-2 pixels in the top-left corner of the image.
% demosaicInterpolate = visionhdl.DemosaicInterpolator(...
%       'SensorAlignment', 'RGGB');
% 
% % Serialize the test image
% % pixIn is a vector of pixel values
% % ctrlIn is a vector of control signal structures
% [pixIn,ctrlIn] = step(frm2pix,frmInput);
% 
% % Prepare to process pixels
% [~,~,numPixelsPerFrame] = getparamfromfrm2pix(frm2pix);
% ctrlOut   = repmat(pixelcontrolstruct,numPixelsPerFrame,1);
% pixOut = zeros(numPixelsPerFrame,3,'uint8');
% 
% % For each pixel in the stream, generate the {R,G,B} triplet
% % Print a progress message every 32 lines
% lineCount = 1;
% for p = 1:numPixelsPerFrame
%     if  ctrlIn(p).hEnd 
%          lineCount = lineCount + 1;
%          if mod(lineCount,32) == 0 
%              fprintf('Processing... line %d\n',lineCount);
%          end
%     end
%     [pixOut(p,:),ctrlOut(p)] = step(demosaicInterpolate,pixIn(p),ctrlIn(p));
% end
% 
% % Create deserializer with format matching that of the serializer
% pix2frm = visionhdl.PixelsToFrame(...
%       'NumComponents',3,...
%       '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)
%     title 'Output Image'
% end
%   See also demosaic.

 
%   Copyright 2014-2016 The MathWorks, Inc.

    methods
        function out=DemosaicInterpolator
            %DemosaicInterpolator Performs Demosaicing of an input image in Bayer
            %  format with the specified alignment. The alignment is identified as
            %  the sequence of R, G and B pixels for the top left 2x2 neighborhood of the input image.
            %
            %  demosaicInterpolate = visionhdl.DemosaicInterpolator returns a System object, demosaicInterpolate,
            %  that performs demosaicing of a Bayer pattern encoded input stream,
            %  based on the input control signals.
            %
            %  demosaicInterpolate = visionhdl.DemosaicInterpolator('PropertyName',PropertyValue,...)
            %  returns a HDL Demosaic System object demosaicInterpolate, with each specified
            %  property set to the specified value.
            %
            %  When Bilinear Interpolation is selected, the interpolated pixel is found
            %  simply by averaging a neighborhood of 3x3 pixels. When Gradient-Corrected
            %  Bilinear Interpolation is selected, the interpolated pixel is found
            %  through a process of averaging, and applying a correction based on the
            %  local gradient of a 5x5 neighborhood. This has a higher complexity,
            %  however achieves a higher PSNR than Bilinear Interpolation.
            %
            %  Step method syntax: 
            %  [pixOut,ctrlOut] = step(demosaicInterpolate,pixIn,ctrlIn)
            %  returns the interpolated R,G,B values based on the input data
            %  and input control signals.
            %
            %  The input pixIn is a scalar image pixel and the data type can be
            %  double/single, unsigned integer, or fixed point. The 
            %  data type of output pixOut follows that of pixIn. Signed data
            %  types are not supported for simulation or HDL code generation. 
            %  ctrlIn and ctrlOut are structures consisting of five 
            %  control signals. See also <a href="matlab:doc visionhdl.FrameToPixels">visionhdl.FrameToPixels</a> or <a href="matlab:doc pixelcontrolstruct">pixelcontrolstruct</a>.   
            %
            %  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.
            %
            %  DemosaicInterpolator methods:
            %
            %   step     - See above description for use of this method
            %   release  - Allow property value and input characteristics changes
            %   clone    - Create demosaicInterpolate object with same property values
            %   isLocked - Locked status (logical)
            %
            %  DemosaicInterpolator properties: -
            %
            %   Algorithm     - Choose algorithm used to perform interpolation.
            %   SensorAlignment - Alignment of the input image.
            %   LineBufferSize   - Size of line buffer memory, equivalent to largest row.
            %
            %  % EXAMPLE:
            % % Form an [R G B] output image from a Bayer format input.
            % % Set the dimensions of the test image
            % frmActivePixels = 256;
            % frmActiveLines = 192;
            % 
            % % Load the source image
            % % This image is in Bayer pattern: each pixel is represented by one value,
            % % alternating green values with red and blue values.
            % frmOrig = imread('mandi.tif');
            % figure
            % imshow(frmOrig,'InitialMagnification',20)
            % title 'Full Image (Scaled Down)'
            % 
            % % Select a portion of the image matching the desired test size.
            % % These offsets select the face of the woman in the image.
            % frmInput = frmOrig(900:899+frmActiveLines,2350:2349+frmActivePixels);
            % figure
            % imshow(frmInput)
            % title 'Input Image'
            % 
            % % Create serializer and specify size of 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 demosaic interpolator
            % % Specify the sequence of color values matching the 2-by-2 pixels in the top-left corner of the image.
            % demosaicInterpolate = visionhdl.DemosaicInterpolator(...
            %       'SensorAlignment', 'RGGB');
            % 
            % % Serialize the test image
            % % pixIn is a vector of pixel values
            % % ctrlIn is a vector of control signal structures
            % [pixIn,ctrlIn] = step(frm2pix,frmInput);
            % 
            % % Prepare to process pixels
            % [~,~,numPixelsPerFrame] = getparamfromfrm2pix(frm2pix);
            % ctrlOut   = repmat(pixelcontrolstruct,numPixelsPerFrame,1);
            % pixOut = zeros(numPixelsPerFrame,3,'uint8');
            % 
            % % For each pixel in the stream, generate the {R,G,B} triplet
            % % Print a progress message every 32 lines
            % lineCount = 1;
            % for p = 1:numPixelsPerFrame
            %     if  ctrlIn(p).hEnd 
            %          lineCount = lineCount + 1;
            %          if mod(lineCount,32) == 0 
            %              fprintf('Processing... line %d\n',lineCount);
            %          end
            %     end
            %     [pixOut(p,:),ctrlOut(p)] = step(demosaicInterpolate,pixIn(p),ctrlIn(p));
            % end
            % 
            % % Create deserializer with format matching that of the serializer
            % pix2frm = visionhdl.PixelsToFrame(...
            %       'NumComponents',3,...
            %       '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)
            %     title 'Output Image'
            % end
            %   See also demosaic.
        end

        function getDiscreteStateImpl(in) %#ok<MANU>
            % Return structure of states with field names as
            % DiscreteState properties.
        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 isOutputComplexImpl(in) %#ok<MANU>
        end

        function isOutputFixedSizeImpl(in) %#ok<MANU>
        end

        function loadObjectImpl(in) %#ok<MANU>
        end

        function outputImpl(in) %#ok<MANU>
            % output
        end

        function resetImpl(in) %#ok<MANU>
            % Initialize states
        end

        function saveObjectImpl(in) %#ok<MANU>
            %Save the public properties
        end

        function setupImpl(in) %#ok<MANU>
        end

        function showSimulateUsingImpl(in) %#ok<MANU>
        end

        function updateImpl(in) %#ok<MANU>
            % update states
        end

        function validateInputsImpl(in) %#ok<MANU>
            %coder.extrinsic('validatecontrolsignals');
        end

    end
    methods (Abstract)
    end
    properties
        %Algorithm Interpolation algorithm
        % Specify the interpolation algorithm as one of
        % ['Gradient-corrected linear'|'Bilinear']
        Algorithm;

        %LineBufferSize Line buffer size
        %   Specify the maximum number of pixels in a horizontal line as an
        %   positive integer. The default value of this property is 2048.
        LineBufferSize;

        %SensorAlignment Sensor alignment
        % Specify the sensor alignment as one of
        % ['GBRG'|'GRBG']|'BGGR'|'RGGB']
        SensorAlignment;

    end
end