Photo Portfolio
ShutterSounds Blog
Resumé (pdf)

Example 8: Variable number gradients interpolation

Variable Number Gradients
Variable Number Gradients

The Variable Number Gradients algorithm is an extension of basic edge-sensing algorithms, calculating a larger number of gradients in more directions. In this implementation, for instance, 8 gradients are used per interpolated color, measuring intensity gradients at every multiple of 45-degree angle (i.e. gradient to the right, top-right, top, top-left, etc.), and only pixels from low-gradient directions are used. For the 8-direction implementation, the sampled pixel area must be expanded to a 5x5 grid compared to the simpler 3x3 grid used for basic edge-sensing - a greater number of directions would require an even greater number of surrounding pixels sampled (to differentiate all the directions).

The Variable Number Gradients algorithm works greatly to reduce artifacts, especially at angled edges in comparison to basic edge-sensing. However, Variable Number Gradients is far more computationally expensive than basic edge-sensing. The greater sampling area of pixels also reduces resolution somewhat - however, this effect should be minimal when used with a Bayer pattern sensor with input light that is pre-filtered by an anti-aliasing filter.

Variable Number Gradients resized 3x
(Resized 3x for clarity)


Choose an algorithm from the left. Feel free to send suggestions/links for new ones to thedailynathan at gmail.

Shown here is the original image for reference, and the simulated Bayer raw data which the different algoriths are run on. The simulated Bayer data is generated by taking only green, red, and blue values from the corresponding pixel in a 2x2 GRGB Bayer pattern. Assuming the image used is a 100% crop taken from an image with the top-left pixel (at position 0,0) being a first green photosite (G1), this should be a fairly accurate representation of the actual raw data (assuming of course, that a camera using a Bayer filter sensor was used, and ignoring any compression losses due to compression to 24-bit true color and possible JPEG lossy compression).

Note that this demo does not quite work as effectively with resized images (this demo resizes images greater than 300x300 for performance reasons), or images not generated from a camera using a Bayer sensor. In these cases, resolution can approach or exceed that of a Bayer sensor and anti-aliasing (AA) filter combination, and severe mosaicing artifacts should be expected to appear, no matter the algorithm.

Original image
Simulated Bayer raw data