Main Content

Demosaic Interpolator

Construct RGB pixel data from Bayer pattern pixel stream

  • Demosaic Interpolator block

Libraries:
Vision HDL Toolbox / Conversions

Description

The Demosaic Interpolator block provides a Bayer pattern interpolation filter for streaming video data. The block implements the calculations using hardware-efficient, multiplier-free algorithms for HDL code generation. You can select a low-complexity bilinear interpolation, or a moderate-complexity gradient-corrected bilinear interpolation.

  • When you select bilinear interpolation, the block operates on a 3-by-3 pixel window using only additions and bit shifts.

  • When you select gradient correction, the block operates on a 5-by-5 pixel window. The calculation is performed using bit shift, addition, and low-order canonical signed digit (CSD) multiplication.

Ports

This block uses a streaming pixel interface with a pixelcontrol bus for frame control signals. This interface enables the block to operate independently of image size and format. All Vision HDL Toolbox™ blocks use the same streaming interface. The block accepts and returns a scalar pixel value and a bus that contains five control signals. The control signals indicate the validity of each pixel and its location in the frame. To convert a frame (pixel matrix) into a serial pixel stream and control signals, use the Frame To Pixels block. For a full description of the interface, see Streaming Pixel Interface.

This block also supports multipixel streams. In that case, the pixel input is a vector of M-by-1 values, where M is number of pixels. The pixel output is a matrix of M-by-3 values. The M value corresponds to the Number of pixels parameter of the Frame To Pixels block, and each output pixel has three components in RGB color space.

Input

expand all

For single pixel streams, specify pixel as a scalar. For multipixel streams, specify pixel as a vector of Number of pixels-by-1 pixel values. Number of pixels can be two, four, or eight. Images in the Bayer format have one color component for each pixel location. Select the sequence of R, G, and B pixels by using the Sensor alignment parameter.

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

Data Types: uint | fixdt(0,W,F) | single | double

The pixelcontrol bus contains five signals. The signals describe the validity of the pixel and its location in the frame. For more information, see Pixel Control Bus.

For multipixel streaming, each vector of pixel values has one set of control signals. Because the vector has only one valid signal, the pixels in the vector must be either all valid or all invalid. The hStart and vStart signals apply to the pixel with the lowest index in the vector. The hEnd and vEnd signals apply to the pixel with the highest index in the vector.

Data Types: bus

Output

expand all

For single pixel streams, the output pixel is a three-element vector of RGB values. For multipixel streams, the output pixel is a matrix of Number of pixels-by-3 RGB values. The block calculates the values of the missing color components for each pixel, using the method you specify in the Interpolation algorithm parameter.

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

Data Types: uint | fixdt(0,W,F) | single | double

The pixelcontrol bus contains five signals. The signals describe the validity of the pixel and its location in the frame. For more information, see Pixel Control Bus.

For multipixel streaming, each vector of pixel values has one set of control signals. Because the vector has only one valid signal, the pixels in the vector must be either all valid or all invalid. The hStart and vStart signals apply to the pixel with the lowest index in the vector. The hEnd and vEnd signals apply to the pixel with the highest index in the vector.

Data Types: bus

Parameters

expand all

Algorithm used to calculate missing pixel values, specified as one of the following:

  • Gradient-corrected linear — Bilinear average, corrected for intensity gradient

  • Bilinear — Average of the pixel values in the surrounding 3-by-3 neighborhood

Select the sequence of R, G, and B pixels that correspond to the 2-by-2 block of pixels in the top-left corner of the input image. Specify the sequence in left-to-right, top-to-bottom order. For instance, the default sequence of RGGB represents an image with this pattern.

Two-by-two grid with R and G across the top and G and B across the bottom

Size of the line memory buffer, specified as a positive integer. Choose a power of two that accommodates the number of active pixels in a horizontal line. If you specify a value that is not a power of two, the buffer uses the next largest power of two.

When you use multipixel input, this value must accommodate (Active pixels per line)/(Number of pixels) + 2.

The total memory size allocated depends on your selection of Interpolation algorithm:

  • Bilinear: 2-by-Line buffer size memory locations

  • Gradient-corrected linear: 4-by-Line buffer size memory locations

Tips

  • When you use a block with an internal line buffer inside an Enabled Subsystem (Simulink), the enable signal pattern must maintain the timing of the pixel stream, including the minimum blanking intervals. If the enable pattern corrupts the timing of the pixel stream, you might see partial output frames, corrupted pixel stream control signals, or mismatches between Simulink® and HDL simulation results. You may need to extend the blanking intervals to accommodate for cycles when the enable is low. For more information, see Configure Blanking Intervals.

Algorithms

expand all

The block pads the edges of the image with symmetric pixel values. For more details, see Edge Padding.

When you use multipixel streaming, the block uses a single line memory and implements a demosiac interpolation algorithm for each of the M input pixels, in parallel. This increase in hardware resources is a trade off for increasing throughput compared to single-pixel streaming.

References

[1] Malvar, Henrique S., Li-wei He, and Ross Cutler. “High-Quality Linear Interpolation for Demosaicing of Bayer-Patterned Color Images.” Microsoft Research, May 2004. http://research.microsoft.com/pubs/102068/Demosaicing_ICASSP04.pdf.

Extended Capabilities

Version History

Introduced in R2015a

expand all

See Also

Blocks

Objects