opencv 美颜

使用OPENCV简单实现具有肤质保留功能的磨皮增白算法


http://www.th7.cn/Program/Android/201709/1247874.shtml


在一个美颜高手那里发现一个美颜算法,他写出了数学表达式,没有给出代码,正好在研究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(temp22, new Scalar(128), temp2);		Core.add(temp22, new Scalar(128, 128, 128, 128), temp2);		// 高斯模糊		Imgproc.GaussianBlur(temp2, temp3, new Size(2 * value2 - 1, 2 * value2 - 1), 0, 0);		// temp4 = image + 2 * temp3 - 255;		Mat temp44 = new Mat();		temp3.convertTo(temp44, temp3.type(), 2, -255);		Core.add(image, temp44, temp4);		// dst = (image*(100 - p) + temp4*p) / 100;		Core.addWeighted(image, p, temp4, 1 - p, 0.0, dst);				Core.add(dst, new Scalar(10, 10, 10), dst);		return dst;	}

	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(temp22, new Scalar(128), temp2);		Core.add(temp22, new Scalar(128, 128, 128, 128), temp2);		// 高斯模糊		Imgproc.GaussianBlur(temp2, temp3, new Size(2 * value2 - 1, 2 * value2 - 1), 0, 0);		// temp4 = image + 2 * temp3 - 255;		Mat temp44 = new Mat();		temp3.convertTo(temp44, temp3.type(), 2, -255);		Core.add(image, temp44, temp4);		// dst = (image*(100 - p) + temp4*p) / 100;		Core.addWeighted(image, p, temp4, 1 - p, 0.0, dst);				Core.add(dst, new Scalar(10, 10, 10), dst);		return dst;	}

测试代码:

 Mat src2 = Imgcodecs.imread("E:/work/qqq/e.jpg");         Mat src3 = face2(src2);                Mat dest = new Mat(new Size(src2.cols()+src3.cols(), src2.rows()), src2.type());         Mat temp1 = dest.colRange(0, src2.cols());         Mat temp2 = dest.colRange(src2.cols(), dest.cols());         src2.copyTo(temp1);         src3.copyTo(temp2);	Imgcodecs.imwrite("E:/work/qqq/z3.jpg",dest);


http://www.cnblogs.com/Imageshop/p/4709710.html

http://www.cnblogs.com/Imageshop/p/3871237.html


  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值