Image Demosaicing: Bilinear Interpolation VS High-Quality Linear Interpolation

you can download the code here.

In this story, I will explain two different algorithms in order to demosaic the images captured by a CCD camera and save based on the Bayer filter. In Fig.1, we show a bggr pixel arrangement according to the Bayer filter. As shown, for the red as well as the blue channel, we keep only 25% of the pixels. For the green channel, 50% of the pixels are kept. By demosaicing the image, we are going to interpolate the missed pixels. We use two different algorithms to demosaic a Beyer image.

Figure.1: Pixels arrangement based on the Bayer filter. (Image source.)
Figure.1: Pixels arrangement based on the Bayer filter. (Image source.)

Bilinear Interpolation

Bilinear interpolating is the easiest method we can use to demosaic a Bayer image. The idea behind this method is that since there is a high probability that the value of a missed pixels has a similarity to the value of its existing adjacent pixels, we can interpolate the missed values in each channel by taking the average of its adjacent pixels. In other words, we start from the red channel, and for any missed values, we take a look over its adjacent pixels and if they contain a value, we take their average and assign the calculated average to the missed pixel.

Figure.2: Bilinear Interpolation Algorithm

As shown in Fig.2, we can use the following equations to interpolate the values of Gx, Bx, and Rx:

High-Quality Linear Interpolation

This method has been proposed by Malvar et al. [1]. The idea behind high-quality interpolation is that for interpolating the missed pixels in each channel, it might not be accurate to use only the adjacent pixels located on the same channel. In other words, for interpolating a green pixel such as Gx in Fig.2, we need to use the value of its adjacent green pixels as well as the value of the existing channel. For example, if at the location of Gx, we have a red value, we have to use that value as well as the adjacent available green values. They called their method gradient correction interpolation.

Finally, they came up with 8 different 5*5 filters shown in Fig.3. We need to convolve the filters to pixels that we want to interpolate.

Figure.3: Filter coefficient for High-Quality Linear Interpolation by [1].

As an example, if we want to estimate the value of a green pixel while we have the value of the red pixel at that location, we need to use the first filter. We need to multiply the weights given in the filters to the values of the given channels and then take their average by dividing by 8 since the summation of the weights of each filter is 8.


[1] Malvar, Henrique S., Li-wei He, and Ross Cutler. “High-quality linear interpolation for demosaicing of Bayer-patterned color images.” 2004 IEEE International Conference on Acoustics, Speech, and Signal Processing. Vol. 3. IEEE, 2004.