Main Content

demosaic

Convert Bayer pattern encoded image to truecolor image

Description

example

RGB = demosaic(I,sensorAlignment) converts the Bayer pattern encoded image, I, to the truecolor image, RGB, using gradient-corrected linear interpolation. sensorAlignment specifies the Bayer pattern.

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.

Examples

collapse all

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)

imshow(J)

Input Arguments

collapse all

Bayer-pattern encoded image, specified as an M-by-N numeric array. I must have at least 5 rows and 5 columns.

Data Types: uint8 | uint16 | uint32

Bayer pattern, specified as one of the values in the following table. Each value 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).

Pattern2–by-2 Sensor Alignment
"gbrg"

Top left pixel is green, top right pixel is blue, bottom left pixel is red, and bottom right pixel is green.

"grbg"

Top left pixel is green, top right pixel is red, bottom left pixel is blue, and bottom right pixel is green.

"bggr"

Top left pixel is blue, top right pixel is green, bottom left pixel is green, and bottom right pixel is red.

"rggb"

Top left pixel is red, top right pixel is green, bottom left pixel is green, and bottom right pixel is blue.

Data Types: char | string

Output Arguments

collapse all

RGB image, returned as an M-by-N-by-3 numeric array of the same data type as I.

References

[1] Malvar, H.S., L. He, and R. Cutler, High quality linear interpolation for demosaicing of Bayer-patterned color images. ICASPP, Volume 34, Issue 11, pp. 2274-2282, May 2004.

Extended Capabilities

Version History

Introduced in R2007b

expand all