在一个美颜高手那里发现一个美颜算法,他写出了数学表达式,没有给出代码,正好在研究OPENCV,顺手实现之。具体过程就是一系列矩阵运算,据说是从一个PS高手那里研究 出来的,一并表示感谢。
这是数学表达式:
Dest =(Src * (100 - Opacity) + (Src + 2 * GuassBlur(EPFFilter(Src) - Src + 128) - 256) * Opacity) /100 ;
public static Mat face2(Mat image) {
Mat dst = new Mat();
// int value1 = 3, value2 = 1; 磨皮程度与细节程度的确定
int value1 = 3, value2 = 1;
int dx = value1 * 5; // 双边滤波参数之一
double fc = value1 * 12.5; // 双边滤波参数之一
double p = 0.1f; // 透明度
Mat temp1 = new Mat(), temp2 = new Mat(), temp3 = new Mat(), temp4 = new Mat();
// 双边滤波
Imgproc.bilateralFilter(image, temp1, dx, fc, fc);
// temp2 = (temp1 - image + 128);
Mat temp22 = new Mat();
Core.subtract(temp1, image, temp22);
// Core.subtract(tem