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

    %% Gamma Correction
% This example performs gamma correction on a thumbnail image.

% Copyright 2015 The MathWorks, Inc.


% Set dimensions of the test image 
frmActivePixels = 64;
frmActiveLines = 48;

% Load the source image
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 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 gamma corrector object  
 gammacorr = visionhdl.GammaCorrector(...
      'Gamma', 1.75);

% 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 stream, compute the gamma corrected pixel value
for p = 1:numPixelsPerFrame  
    [pixOut(p),ctrlOut(p)] = step(gammacorr,pixIn(p),ctrlIn(p));
end

% 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