CCD Bayer Masks

Consumer CCD cameras obtain colour information by sampling the image through a Bayer filter mask. The classic mask is RGB in a mosaic with half the cells sampling green and a quarter each on red and blue. There is more detail of other related colour filter masks at Pinnacles website. One of the better online descriptions of digital cameras and colour aliasing is by Silicon Imaging.

The repeating unit over a square of four cells is

G B
R G

Here is a sample of an image taken with a Kodak DC-120 camera which allows access to the original CCD data in it's uncompressed mode. The DC-120 has rectangular pixels which further complicates things but is ignored here. All the images are displayed zoomed 2x so that the pixelation and artefacts are obvious. The sample images are all PNG files so if you browser doesn't support them you are out of luck.

The original image direct from the camera has intensities in the RGB in ratios 1:2:1 which gives it a distinct green cast. There is twice as much green data.

IMAGE7.PNG

The channels can be split using an image manipulation program to separate RGB images. They have been brightness and contrast adjusted to make them clearer.

RED8.PNG BLUE8.PNG


After decreasing the green intensity by 50% the colour balance of the raw Bayer mask data is about right.

IMAGE8.PNG

Using a simple minded linear interpolation of the green data with the filter kernel.

0 1 0
1 4 1
0 1 0

And the red and blue data with the filter kernel

1 2 1
2 4 2
1 2 1

In both cases normalised by dividing by 4. These filters create the effect of linear interpolation between the measured pixels. A rough version of the colour image with RGB values for every pixel is obtained.

I also noticed something peculiar in Paintshop Pro v5. Or at least something I don't understand.

The following operations do not give equivalent results !

#1 Separate to R,G,B images - apply filters to R, G, B as separate planes - combine RGB to final image.

#2 Apply user defined filters to data by selecting G or R&B acting on the original data.

Results on the left are from method #1 and on the right from method #2

Clearly method #2 works best, but why are the results different ?

I don't understand why the red has lost out in the deal. White and blue look to be about right but the red is too weak. The left hand weather board looks fine, but the right hand one shows colour aliasing fringes from the asymmetric red and blue sampling.

IMAGE9.PNG

And then unsharp masking to recover some resolution and interpolating the non square pixels yields something close to the final image.

IMAGE12.PNG

Kodaks own KDC to BMP makes a much better job of it, and cleverly manages to avoid Bayer mask artefacts on the diagonal white board on the right hand side of the picture.

IMAGE10.PNG

Clearly the Kodak conversion from raw CCD data to BMP is doing some additional work and has made a very good job of eliminating the colour fringes that the naive treatment would have produced.


Email to Martin Brown

Send feedback suggestions and comments to Martin Brown
Last modified 22nd Jan 2013