Main Content

Demosaic

Demosaic Bayer format images

  • Demosaic block

Libraries:
Computer Vision Toolbox / Conversions

Description

The Demosaic block takes images in Bayer format and outputs RGB images. The block performs this operation using a gradient-corrected linear interpolation algorithm or a bilinear interpolation algorithm. This figure illustrates a 4-by-4 image in Bayer format with each pixel labeled R, G, or B.

Illustration of 4-by-4 image in Bayer format with each pixel labeled R, G, or B.

Examples

Ports

Input

expand all

Image to demosaic, specified as a 2-D numeric matrix. The size requirements for the matrix depend on the value of the Interpolation algorithm parameter.

  • If the value of Interpolation algorithm is Bilinear, the matrix must have three or more rows and three or more columns.

  • If the value of Interpolation algorithm is Gradient-corrected linear, the matrix must have five or more rows and five or more columns.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fixed point

Output

expand all

Red color channel of processed image, returned as a 2-D numeric matrix of the same size and data type as I.

Dependencies

To enable this port, set the Output image signal parameter to Separate color signals.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fixed point

Green color channel of processed image, returned as a 2-D numeric matrix of the same size and data type as I.

Dependencies

To enable this port, set the Output image signal parameter to Separate color signals.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fixed point

Blue color channel of processed image, returned as a 2-D numeric matrix of the same size and data type as I.

Dependencies

To enable this port, set the Output image signal parameter to Separate color signals.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fixed point

Multidimensional processed image, returned as a 3-D numeric matrix of the same data type as I. If the input image I has the dimensions M-by-N, then Image has the dimensions M-by-N-by-P, where P is the number of color channels.

Dependencies

To enable this port, specify the Output image signal parameter as One multidimensional signal.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fixed point

Parameters

expand all

Main

Specify the algorithm the block uses to calculate the missing color information. If you select Bilinear, the block spatially averages the values of the neighboring pixels of a missing color value to calculate its color information.

If you select Gradient-corrected linear, the block uses a Weiner approach to minimize the mean-squared error in the interpolation. This method performs well on the edges of objects in the image. Both methods use symmetric padding at the image boundaries. For more information, see the Image Pad block reference page.

Specify the alignment of the input image. 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 image. Specify the sequence in left-to-right, top-to-bottom order. For example, for this image, you would select BGGR.

Illustration of 4-by-4 image in Bayer format with each pixel labeled R, G, or B.

Specify how to output the RGB image. Given an M-by-N input image, this parameter affects the output of this block in these ways.

  • One multidimensional image — The block has a single port, Image, that outputs an M-by-N-by-P RGB image, where P is the number of color channels.

  • Separate color signals — The block has three ports, R, G, and B, that each output one M-by-N color channel of the RGB image.

Data Types

For details on the fixed-point block parameters, see Specify Fixed-Point Attributes for Blocks (DSP System Toolbox).

Select this parameter to prevent the fixed-point tools from overriding the data types you specify in this block. For more information, see Lock the Output Data Type Setting (Fixed-Point Designer).

Block Characteristics

Data Types

double | fixed point | integer | single

Multidimensional Signals

yes

Variable-Size Signals

no

References

[1] Malvar, H.S., Li-wei He, and R. Cutler. “High-Quality Linear Interpolation for Demosaicing of Bayer-Patterned Color Images.” In 2004 IEEE International Conference on Acoustics, Speech, and Signal Processing, 3:iii-485–88. Montreal, Que., Canada: IEEE, 2004. https://doi.org/10.1109/ICASSP.2004.1326587.

[2] Gunturk, B.K., J. Glotzbach, Y. Altunbasak, R.W. Schafer, and R.M. Mersereau. “Demosaicking: Color Filter Array Interpolation.” IEEE Signal Processing Magazine, 22, no. 1 (January 2005): 44–54. https://doi.org/10.1109/MSP.2005.1407714.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.

Version History

Introduced in R2006b

See Also