Documentation Center

  • Trial Software
  • Product Updates

demosaic

Convert Bayer pattern encoded image to truecolor image

Syntax

RGB = demosaic(I, sensorAlignment)

Description

RGB = demosaic(I, sensorAlignment) converts a Bayer pattern encoded image to a truecolor image using gradient-corrected linear interpolation. I is an M-by-N array of intensity values that are Bayer pattern encoded. I must have at least 5 rows and 5 columns.

A Bayer filter mosaic, or color filter array, refers to the arrangement of color filters that let each sensor in a single-sensor digital camera record only red, green, or blue data. The patterns emphasize the number of green sensors to mimic the human eye's greater sensitivity to green light. The demosaic function uses interpolation to convert the two-dimensional Bayer-encoded image into the truecolor image, RGB, which is an M-by-N-by-3 array.

sensorAlignment is one of the following text strings that specifies the Bayer pattern. Each string represents the order of the red, green, and blue sensors by describing the four pixels in the upper-left corner of the image (left-to-right, top-to-bottom).

Value2–by-2 Sensor Alignment
'gbrg'
'grbg'
'bggr'
'rggb'

Class Support

I can be uint8 or uint16, and it must be real. RGB has the same class as I.

Examples

expand all

Convert a Bayer Pattern Encoded Image To an RGB Image

Convert a Bayer pattern encoded image that was photographed by a camera with a sensor alignment of 'bggr' .

I = imread('mandi.tif');
J = demosaic(I,'bggr');
imshow(I);
figure, imshow(J);

Was this topic helpful?