Main Content

visionhdl.GammaCorrector

Apply or remove gamma correction

Description

visionhdl.GammaCorrector applies or removes gamma correction on a stream of pixels. Gamma correction adjusts linear pixel values so that the modified values fit a curve. The de-gamma operation performs the opposite operation to obtain linear pixel values.

To apply or remove gamma correction:

  1. Create the visionhdl.GammaCorrector object and set its properties.

  2. Call the object with arguments, as if it were a function.

To learn more about how System objects work, see What Are System Objects?

Creation

Description

corrector = visionhdl.GammaCorrector returns a System object™ that applies default gamma correction on a stream of pixels.

corrector = visionhdl.GammaCorrector(Name,Value) returns a gamma correction System object, corrector, with properties set using one or more name-value pairs. Enclose each property name in single quotes.

Example: corrector = visionhdl.GammaCorrector('LinearSegment',false) creates a gamma correction object that does not use a linear segment in the gamma curve.

example

corrector = visionhdl.GammaCorrector(operation,gammaValue,Name,Value) returns a gamma correction System object with the Correction property set to operation, the Gamma property set to gammaValue, and additional options specified by one or more name-value pairs.

Properties

expand all

Unless otherwise indicated, properties are nontunable, which means you cannot change their values after calling the object. Objects lock when you call them, and the release function unlocks them.

If a property is tunable, you can change its value at any time.

For more information on changing property values, see System Design in MATLAB Using System Objects.

Direction of intensity curve adjustment, specified as either:

  • 'Gamma' — Apply gamma correction.

  • 'De-gamma' — Remove gamma correction.

Target or current gamma value, specified as a scalar value greater than or equal to 1.

  • When you set Correction to 'Gamma', set this property to the target gamma value of the output video stream.

  • When you set Correction to 'De-gamma', set this property to the gamma value of the input video stream.

Option to include a linear segment in the gamma curve, specified as true or false. When you set this property to true, the gamma curve has a linear portion near the origin.

Point where the gamma curve and linear segment meet, specified as a scalar pixel value between 0 and 1, exclusive.

Dependency

To enable this property, set LinearSegment to true.

Usage

Description

[pixelout,ctrlout] = corrector(pixelin,ctrlin) returns the intensity value of a pixel after gamma correction, and the control signals associated with the pixel. The input, pixelin, and output, pixelout, are scalar values representing a single pixel.

This object uses a streaming pixel interface with a structure for frame control signals. This interface enables the object to operate independently of image size and format and to connect with other Vision HDL Toolbox™ objects. The object accepts and returns a scalar pixel value and control signals as a structure containing five signals. The control signals indicate the validity of each pixel and its location in the frame. To convert a pixel matrix into a pixel stream and control signals, use the visionhdl.FrameToPixels object. For a description of the interface, see Streaming Pixel Interface.

Input Arguments

expand all

Input pixel stream, specified as a scalar intensity value. Integer and fixed-point data types larger than 16 bits are not supported.

You can simulate System objects with a multipixel streaming interface, but you cannot generate HDL code for System objects that use multipixel streams. To generate HDL code for multipixel algorithms, use the equivalent Simulink® blocks.

The software supports double and single data types for simulation, but not for HDL code generation.

Data Types: uint8 | uint16 | int8 | int16 | fi | single | double

Control signals accompanying the input pixel stream, specified as a pixelcontrol structure containing five logical data type signals. The signals describe the validity of the pixel and its location in the frame. For more details, see Pixel Control Structure.

Data Types: struct

Output Arguments

expand all

Gamma-corrected intensity of a single pixel, specified as a scalar value. The data type of the output pixel is the same as the data type of pixelin.

Data Types: uint8 | uint16 | int8 | int16 | fi | single | double

Control signals accompanying the output pixel stream, returned as a pixelcontrol structure containing five logical data type signals. The signals describe the validity of the pixel and its location in the frame. For more details, see Pixel Control Structure.

Data Types: struct

Object Functions

To use an object function, specify the System object as the first input argument. For example, to release system resources of a System object named obj, use this syntax:

release(obj)

expand all

stepRun System object algorithm
releaseRelease resources and allow changes to System object property values and input characteristics
resetReset internal states of System object

Examples

collapse all

This example performs gamma correction on a thumbnail image.

Load the source image from a file. Select a portion of the image matching the desired test size.

frmOrig = imread('rice.png');
frmActivePixels = 64;
frmActiveLines = 48;
frmInput = frmOrig(1:frmActiveLines,1:frmActivePixels);
figure
imshow(frmInput,'InitialMagnification',300)
title 'Input Image'

Create a serializer object and specify the 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 a gamma corrector object.

 gammacorr = visionhdl.GammaCorrector(...
      'Gamma', 1.75);

Serialize the test image by calling the serializer object. pixIn is a vector of intensity values. ctrlIn is a vector of control signal structures.

[pixIn,ctrlIn] = frm2pix(frmInput);

Prepare to process pixels by preallocating output vectors.

[~,~,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)] = gammacorr(pixIn(p),ctrlIn(p));
end

Create a deserializer object with a format matching that of the serializer. Convert the pixel stream to an image frame by calling the deserializer object. Display the resulting image.

pix2frm = visionhdl.PixelsToFrame(...
      'NumComponents',1,...
      'VideoFormat','custom',...
      'TotalPixelsPerLine',frmActivePixels+10,...
      'ActivePixelsPerLine',frmActivePixels,...
      'ActiveVideoLines',frmActiveLines);  
[frmOutput,frmValid] = pix2frm(pixOut,ctrlOut);
if frmValid
    figure
    imshow(frmOutput, 'InitialMagnification',300)
    title 'Output Image'
end

Algorithms

expand all

For the equations used for gamma correction, see Gamma Correction (Computer Vision Toolbox).

To save hardware resources, the object implements the gamma correction equation as a lookup table. The lookup table maps each input pixel value to a corrected output value.

Extended Capabilities

Version History

Introduced in R2015a

expand all

See Also

Blocks

Objects

Functions