# An Effective Directional Residual Interpolation Algorithm for Color Image Demosaicking
## 3 The Proposed Demosaicking Algorithm
### The Calculation Process of Directional Weights  
We can get an observed pixel value and two directionally estimated values at each pixel after Step 1. In this section, we use the directional color difference estimations and the absolute color difference gradients to calculate the directional weights. The process is shown in Figure 5.  
Figure 4: The horizontal R pixel value interpolation: (**a**) [PERSON]’s interpolation equation [15]; (**b**) MLRI [21]. The directional color difference estimations can be calculated by Equation (11) in MLRI. \[\widetilde{\Delta}_{\mathrm{g,r}}^{\mathrm{H}}(i,j)=\left\{ \begin{array}{l}G_{i, j}^{\mathrm{H}}-R_{i,j},\text{ G is interpolated}\\ G_{i,j}-R_{i,j}^{\mathrm{H}},\text{ R is interpolated}\end{array} \right., \widetilde{\Delta}_{\mathrm{g,r}}^{\mathrm{V}}(i,j)=\left\{ \begin{array}{l}G _{i,j}^{\mathrm{V}}-R_{i,j},\text{ G is interpolated}\\ G_{i,j}-R_{i,j}^{\mathrm{V}},\text{ R is interpolated}\end{array} \right., \tag{11}\]  
where \(\widetilde{\Delta}_{\mathrm{g,r}}^{\mathrm{H}}\) is the horizontal color difference estimation between G and R image, and \(\widetilde{\Delta}_{\mathrm{g,r}}^{\mathrm{V}}\) is the vertical color difference estimation between G and R image. The effective combination of the directional color difference estimations is the most important factor of a successful algorithm. However, the horizontally estimated R pixel value \(R^{\mathrm{H}}\) in Equation (11) is not completely the same as the actual value. There are differences between the missing actual value during imaging and the reconstructed value. To reduce the influence of differences and to get estimated values, we reduce the weight of \(R^{\mathrm{H}}\) in Equation (11). Compared with MLRI, we use Equation (12) to calculate the directional color difference estimations. \[\widetilde{\Delta}_{\mathrm{g,r}}^{\mathrm{H}}(i,j)=\left\{ \begin{array}{l}G _{i,j}^{\mathrm{H}}-R_{i,j}/2,\text{ G is interpolated}\\ G_{i,j}-R_{i,j}^{\mathrm{H}}/2,\text{ R is interpolated}\end{array} \right., \widetilde{\Delta}_{\mathrm{g,r}}^{\mathrm{V}}(i,j)=\left\{ \begin{array}{l}G _{i,j}^{\mathrm{V}}-R_{i,j}/2,\text{ G is interpolated}\\ G_{i,j}-R_{i,j}^{\mathrm{V}}/2,\text{ R is interpolated}\end{array} \right.. \tag{12}\]  
Similarly, we can calculate the directional color difference estimations between G and B image. As a result, the observed pixel value and the two directional color difference estimations are generated at each pixel. It provides convenience for the reconstruction of missing G pixel values. Furthermore, the directional estimation may be inaccurately calculated because of the false edge information in irregular edges. However, experimental results show that Equation (12) can effectively reduce this influence of it. From the above steps, we use the directional color difference estimations to calculate the color difference gradients. The absolute color difference gradients at pixel coordinates \((i,j)\) are given by:  
\[D_{i,j}^{\mathrm{H}}=\Big{|}\widetilde{\Delta}^{\mathrm{H}}(i,j-1)-\widetilde{ \Delta}^{\mathrm{H}}(i,j+1)\Big{|},D_{i,j}^{\mathrm{V}}=\Big{|}\widetilde{ \Delta}^{\mathrm{V}}(i,j-1)-\widetilde{\Delta}^{\mathrm{V}}(i,j+1)\Big{|}, \tag{13}\]  
where \(\widetilde{\Delta}^{\mathrm{H}}(i,j)\) is the horizontal color difference estimation in \((i,j)\), and \(\widetilde{\Delta}^{\mathrm{V}}(i,j)\) is the vertical color difference estimation in \((i,j)\). Then we use the absolute color difference gradients to calculate horizontal and vertical weights. As we all know, the average without directional weights usually causes aliasing in the edge and the texture areas, so it is necessary to distinguish direction to avoid aliasing. In a word, the values around the target pixel are averaged according to different weights. It can effectively reduce aliasing which is caused by the abrupt color change. Thus, the weight will become smaller when the abrupt color change becomes larger.