| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Image Processing Toolbox |
| Contents | Index |
| Learn more about Image Processing Toolbox |
RGB = demosaic(I, sensorAlignment)
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).
| Value | 2–by-2 Sensor Alignment |
|---|---|
| 'gbrg' |
![]() |
| 'grbg' |
![]() |
| 'bggr' |
![]() |
| 'rggb' |
![]() |
I can be uint8 or uint16, and it must be real. RGB has the same class as I.
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);Bayer Pattern Encoded Image

Truecolor Image

![]() | decorrstretch | dicomanon | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2010- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |