About demosaicing algorithms; a novel demosaicing technique

Boris van Schooten, boris@13thmonkey.org

Demosaicing by shifting the destination grid by 1/2 pixel

My first try at demosaicing was when I tried to produce B/W images which are sharper than desaturated colour images by using the raw CCD information in a special way. While the attempt was mildly succesful, I didn't manage to get an essentially higher resolution. I did come up with a very nice idea for a demosaicing algorithm though. It turned out to be quite useable for colour demosaicing as well.

I tried to use the green CCD pixels to construct a B/W image. As it turned out, demosaicing artifacts are already problematic here, even without having to worry about colour. I tried a bilinear interpolation algorithm, which produced major "jaggies", aka "zipper artifacts". Clearly, a problem here is that half the pixels in the reconstructed picture coincide with CCD pixels, while the other half have to be estimated by looking at neighbouring CCD pixels. If you use bilinear interpolation, you reconstruct the missing CCD pixels by averaging the four neighbouring CCD pixels. Averaging however means loss of contrast, and these averaged pixels usually have intensities somewhere in-between neighbouring pixels: in other words, zipper artefacts.

We might say that, the problem here is that the distance between each destination pixel and each source pixels varies per pixel (that is, it either coincides perfectly or it has distance 1 from the nearest source pixels). The quality of these two different types of pixels is noticably different. From an information point of view, the accuracy of the information for the two kinds of pixels is different, and the inaccuracy of the inaccurate pixels shows with this simple interpolation algorithm. So, do we need a more advanced algorithm? Not necessarily! At this point, I came up with the idea of equalising the distance between source and destination for the different destination pixels. How? By shifting the destination grid 1/2 pixel to the right and bottom. Now, each destination pixel overlaps exactly two source pixels, and, by linear interpolation, each pixel may be determined by averaging these two pixels. Voila, gone zipper artifacts! This simple technique produces sharp images with only minor diagonal "jaggies", and which are nearly as good as those from the camera, and sometimes have even better detail resolving power. This is quite remarkable, as a *lot* of research and development has gone in demosaicing algorithms, and the Canon camera I used has some of the best algorithms.

Test images for green channel demosaicing algorithm


Figure 1: demosaicing green with and without shifting the destination pixels.
The grey squares are the locations of the destination pixels, the shade of grey indicates the distance from the nearest source pixels (i.e. accuracy).

The 1/2 pixel grid shift has another advantage: the difference between red and blue CCD pixels and the different final image pixels is also equalised. In fact, each destination pixel overlaps with exactly one red and one blue CCD pixel. Using bilinear interpolation on the red and blue channel produced a nice colour image with acceptable artifacts (better than some cameras).

Below are some test images done with this algorithm. Note that the interpolated images were sharpened in the luminance channel, and otherwise unmodified.

Colour demosaicing comparison
More test images...
Image1 Image2 Image3

Future directions

We may use improved interpolation algorithms to get rid of the artifacts, producing more optimal results. But on the other hand, most such algorithms work by making more assumptions about the data. To reduce colour artifacts, one usually assumes that the colour in the picture makes relatively smooth transitions, so that we may use a larger area of the CCD to estimate the colour.


The adapted CRW program (original by Dave Coffin) (This was made to work on a G3, it will also work on other cameras that have the same red/green/blue CCD pattern.

Boris van Schooten
boris@13thmonkey.org