This algorithm tries to improve Bilinear Interpolation by taking in account the artifacts caused by interpolating across edges in the image. It uses a method to determine whether to horizontally or vertically interpolate a value for the “missing” pixels in the green channel, hence the name.

Overall, Green Edge Directed Interpolation provides significantly less artifacts than Bilinear Interpolation, while having a sharper image and a higher processing time.

Associated Files

The class contains two methods that we can choose to run the desired interpolation.

1 Constructor

Green Edge Directed Interpolation shares the same constructor code as Bilinear Interpolation.

2 Pattern Offsets

Green Edge Directed Interpolation uses the same pattern offsets as Bilinear Interpolation.

3 Green Edge Directed Interpolation

The Process method executes the Green Edge Directed Interpolation. It is practically identical to Bilinear Interpolation. In fact, the algorithm uses Bilinear Interpolation on Red and Blue channels.

As we know from Bilinear Interpolation, it starts by running two of the following four methods for demosaicing: DebayerBottomRight, DebayerBottomLeft, DebayerTopLeft, and DebayerTopRight, in accordance to the image’s Bayer pattern. Those methods are used to demosaic the Red and Blue channels of the image.

Afterwards, the Green channel is demosaiced with DebayerGreen. This method is the only, albeit important, difference between Bilinear Interpolation and Green Edge Directed Interpolation.

Green channel demosaicing
In the case of Green channel, there are two “missing” pixels per block, with two calculation cases:
  • Horizontal Interpolation
    • The average value of the sensels at the top and bottom of the “missing” pixels is the new value for the “missing” pixel.
  • Vertical Interpolation
    • The average value of the sensels at the left and right of the “missing” pixels is the new value for the “missing” pixel.

To decide whether to horizontally or vertically interpolate the value, the algorithm calculates the horizontal and vertical gradations:

  • hGrad = abs(leftSensel - rightSensel)
  • vGrad = abs(topSensel - bottomSensel)

Finally, the “missing” pixel value will be hValue if vGrad is higher than hGrad. If that is not the case, the value will be vValue. In other words, it will interpolate along the edge and not across the edge.

  • If vGrad > hGrad:
    • hValue -> missingPixel = (leftSensel + rightSensel) / 2
  • Else:
    • vValue -> missingPixel = (topSensel + bottomSensel) / 2

Finally, the last step is to demosaic the borders, using DemosaicBorders for each color channel. This method simply copies the nearest pixel that is not in the image border.