An approach to the implementation of camera real-time filter on Android platform (eight)--Simple beauty filter

Source: Internet
Author: User

Beauty includes grinding skin, whitening, thin face and other effects, including the grinding algorithm in many blogs are introduced

For example:

The experiment of the double exponential edge smoothing filter used in the skin-grinding algorithm

The implementation of selective fuzzy and its algorithm

Image denoising based on local mean-variance correlation information and its application in real-time skin beauty algorithm

Guide Filter Grinding Skin

Recursive double-sided filter grinding skin

The above blog has the relevant code/formula, the test if the selection of the appropriate parameters have a good effect, unfortunately the level of limited has not yet achieved in the shader real-time effect ~

Observe the 美图秀秀 and Huawei cameras and other camera apps, found that the real-time beauty effect is not as good as PC-side and mobile-end post-processing, there may be few solutions in this area or the demand is not high.

Here's a simple way to deal with the beauty filter.


One. Fuzzy processing


Simple Gaussian blur or bilateral filtering can be used here to easily refer to the Gaussian blur in the gpuimage, or to optimize the code above to the extent that it can be executed in real time


Two. Grayscale the blurred image


<span style= "FONT-SIZE:12PX;" >const mediump vec3 luminanceweighting = VEC3 (0.2125, 0.7154, 0.0721); </span>

This is where we set three elements of the vector, for our brightness to save the color specific gravity. These three values add up to 1, so that we can calculate the brightness as a value between 0.0-1.0. Note that the median value, which is the value of green, uses 70% of the color weight, and blue uses only 10% of it. This is the Sony Trinitron data, the more general factor is the ITU HDTV standard 0.2125, 0.7154, 0.0721 and for CRT display non-linear color 0.299, 0.587, 0.114).


Using the dot multiplication operation in GLSL, the luminance value of this pixel synthesis is calculated.


LOWP float Satura = 0.7; LOWP vec3 Greyscalecolor = VEC3 (luminance);  

Create a three value that is the VEC3 of the luminance information, combining all the fragments together. To determine what each new color is, use the Mix function (Mix (x, Y, a): X, y linear aliasing, X (1-a) + y*a;). The MIX function combines the grayscale values we just computed with the initial texture color and the saturation information we get.

PS: The above code can be found in gpuimage


Three. Whitening Map


Find out when the color curve can whiten your photos, such as this article discusses some whitening methods. PS Level High students here can design their own results. Here is a mapping table from an app that is ready to be taken out. Pass it as a texture to the fragment shader.

                byte[] Arrayofbyte = new byte[1024]; Int[] ArrayOfInt1 = {95, 95, 96, 97, 97, 98, 99, 99, 100, 101, 101, 102, 103, 104, 104, 105, 106, 106, 107, 108, 108, 109 , 110, 111, 111, 112, 113, 113, 114, 115, 115, 116, 117, 117, 118, 119, 120, 120, 121, 122, 122, 123, 124, 124, 125, 126, 127, 127, 128, 129, 129, 130, 131, 131, 132, 133, 133, 134, 135, 136, 136, 137, 138, 138, 139, 140, 140, 141, 142, 143, 14  3, 144, 145, 145, 146, 147, 147, 148, 149, 149, 150, 151, 152, 152, 153, 154, 154, 155, 156, 156, 157, 158, 159, 159, 160, 161, 161, 162, 163, 163, 164, 165, 165, 166, 167, 168, 168, 169, 170, 170, 171, 172, 172, 173, 174, 175, 175, 176, 177, 1 77, 178, 179, 179, 180, 181, 181, 182, 183, 184, 184, 185, 186, 186, 187, 188, 188, 189, 190, 191, 191, 192, 193, 193, 194 , 195, 195, 196, 197, 197, 198, 199, 200, 200, 201, 202, 202, 203, 204, 204, 205, 206, 207, 207, 208, 209, 209, 210, 211, 211, 212, 213, 213, 214, 215, 216, 216, 217, 218, 218, 219, 220, 220, 221, 222, 223, 223, 224, 225, 225, 226, 227, 227, 228, 229, 229, 230, 231, 232, 232, 233, 234, 234, 235, 236, 236, 237, 238, 239, 239, 240, 241, 241, 242, 243, 243, 244, 245, 245, 246, 247, 248, 248, 249, 250, 250, 251, 252, 252, 253, 254, 255, 255, 25                5, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255};  Int[] ArrayOfInt2 = {0, 0, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8, 8, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 20, 20, 20, 21  2, 22, 23, 23, 23, 24, 24, 24, 25, 25, 25, 25, 26, 26, 27, 27, 28, 28, 28, 28, 29, 29, 30, 29, 31, 31, 31, 31, 32, 32, 33, 33, 34, 34, 34, 34, 35, 35, 36, 36, 37, 37, 37, 38, 38, 39, 39, 39, 40, 40, 40, 41, 42, 42, 43, 43, 44, 44, 45  6, 47, 47, 48, 48, 49, 50, 51, 51, 52, 52, 53, 53, 54, 55, 55, 56, 57, 57, 58, 59, 60, 60, 61, 62, 63, 63, 64, 65, 66, 67, 68, 68, 69, 70, 71, 72,73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 88, 89, 90, 91, 93, 94, 95, 96, 97, 98, 100, 101, 103, 104, 105, 1 07, 108, 110, 111, 113, 115, 116, 118, 119, 120, 122, 123, 125, 127, 128, 130, 132, 134, 135, 137, 139, 141, 143, 144, 146 , 148, 150, 152, 154, 156, 158, 160, 163, 165, 167, 169, 171, 173, 175, 178, 180, 182, 185, 187, 189, 192, 194, 197, 199,                201, 204, 206, 209, 211, 214, 216, 219, 221, 224, 226, 229, 232, 234, 236, 239, 241, 245, 247, 250, 252, 255};                  for (int i = 0; i < i++) {arrayofbyte[(I * 4)] = ((byte) arrayofint1[i]);                  arrayofbyte[(1 + i * 4)] = ((byte) arrayofint1[i]);                  arrayofbyte[(2 + i * 4)] = ((byte) arrayofint2[i]);                arrayofbyte[(3 + i * 4)] =-1; } gles20.glteximage2d (gles20.gl_texture_2d, 0, Gles20.gl_rgba, 1, 0, Gles20.gl_rgba, Gles20.gl_unsigne       D_byte, Bytebuffer.wrap (Arrayofbyte));

Take out in the fragment shader


four. Mixing


Mix the mapped RGB with the first step blur (the code can take the Overblend in Gpuimage)

The multiply (Multiply) and filter (screen) are two basic blending modes used to darken and brighten the picture. The combination of them can also form more complex blending modes, such as overlay (Overlay) and soft Light (Soft).

Multiply-multiplies the pixels of the two-layer image and finally gets a darker image. This pattern is symmetric, which means that the exchange base and the blend color get the same result.

F (b) = AB, where a is the base color and B is a blend color.

Filter--First, the pixel values of the two-layer images are complementary, then multiply them, and finally the complementary number. This is the opposite of the result from the multiply. It will get a brighter image.

F (b) =1-(1-a) (1-b), where a is the base color and B is a blend color.

Overlay-combines multiply and filter blending modes. The bright part of the base color is brighter, and the darker part is darker.

F (A, B) when a<0.5, then 2ab, otherwise N (1-a) (1-b), where a is the base color, and a is a blend.


can then be drawn to the screen, you can also output to the texture and then two times filter processing again grinding skin, etc.


Five.



An approach to the implementation of camera real-time filter on Android platform (eight)--Simple beauty filter

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.