Continued with the previous project - image processing using OpenGL ES shaders, I studied and implemented another two interesting filters: artistic painting effect and diffuse glow effect.
Artistic Painting Effect
The idea is still taken from the popular book Graphics Shaders, which is followed closely from the very start of the project. The artist effect is achieved by scanning the pixels around the centre one, and take either the brightest or darkest to replace the centre. The patch shape is critical for the final result. The sample code is using a 3x3 square patch. Since OpenGL ES shaders does not support non-constant indexed array, the implementation has to be copied through all the pixels in the patch (the codes will be super long if a larger patch is used).
Diffuse Glow Effect
Diffuse glow effect, as termed in Photoshop, gives the image a smooth, dreamy and lightening effect. It softens the skin color if applied to portrait images. I have done some research on Google, however could not find a detail explanation of the mechanism of this effect. Then I dig deep into the codes of the open source image processing software GIMP (It can be cloned from git by git clone git://git.gnome.org/gimp). The effect is termed as Soft Glow Filter in GIMP, and the source code can be found under the plug-in/common folder. Modified for an efficient implementation using Shaders, the steps are summaried:
1. Gaussian Blur
A 3x3 Gaussian Blur box is used for a fast implementation. Slightly adjust the pixel size here to achieve a stronger blurring effect.
Mix with luminance image of itself we can get the saturated image.
3. Sigmoidal Transfer
A sigmoid function, which has an “S” shape, is defined as below. The parameters are adopted from the open source codes of GIMP. (It is a curve adjusting process)
4. Screen Blend
With screen blend mode the values of the pixels in the two layers are negated, multiplied, and then negated again. The result is a brighter picture:
It is fun to dig into the open source code and reverse engineered out the algorithms and implemented on the faster GPU chip. I hope I could spend more time to do this, but unfortunately I have to deal with some more serious projects to produce papers, so sad. There are two very good open source projects that I get inspirations from: InstaCam by Harri Smatt, and LightBox.