利用 mediapipe 進行處理
規劃
1.先把人臉辨識,然後取出框框
2.把框框內的人臉,進行美容
-高反差保留
(1)曝光度調整
(2)綠色與藍色,疊加
(3)YUCIHighPassSkinSmoothingMaskBoost
-調整圖像亮度
-混合
3.把人臉的嘴巴,進行塗紅
4.把人臉的眼睛塗黑

把圖片內的人臉變漂亮

import numpy as np
import cv2
from scipy.interpolate import CubicSplinefrom PIL import Image
import matplotlib.pyplot as plt
import time
from PIL import ImageFilterdef np2pil(numpy_image):return Image.fromarray(np.uint8(numpy_image*255.0)).convert('RGB')img = cv2.imread('./images/person2.jpg')scale_percent = 50 # percent of original size
width = int(img.shape[1] * scale_percent / 100)
height = int(img.shape[0] * scale_percent / 100)
dim = (width, height)   # resize image
img = cv2.resize(img, dim, interpolation = cv2.INTER_NEAREST)timea = time.time()input_img = np.array(img[...,::-1]/255.0,dtype=np.float32) # to rgb  變成0-1之間  [x,y,bgr] (2320, 3088, 3)
ea_img = input_img * pow(2,-1.0)  # 把畫面變黑 少一半# YUCIGreenBlueChannelOverlayBlend  进行绿色和蓝色通道的混合叠加  ba_img
base = ea_img[...,1]   #
overlay = ea_img[...,2]  #
ba = 2.0*overlay*base   #
ba_img = np.zeros((ba.shape[0],ba.shape[1],3),dtype=np.float32)
ba_img[...,0] = ba
ba_img[...,1] = ba
ba_img[...,2] = ba# YUCIHighPass  高通滤波YUCIHighPass的环节,非常简单,先高斯模糊一下子,然后跟原图做个混合  blur_img
# 先进行高斯模糊
radius = int(np.ceil(7.0*input_img.shape[0]/750.0))
pil_img = np2pil(ba_img)
pil_blur = pil_img.filter(ImageFilter.GaussianBlur(radius))
blur_img = np.asarray(pil_blur,np.float32)/255.0# 再进行YUCIHighPass    hp_img = ba_img - blur_img + 0.5
hp_img = ba_img - blur_img + 0.5#紀錄時間  0.6
timeb = time.time()
print("hpss_img for blue green", timeb-timea)# YUCIHighPassSkinSmoothingMaskBoost
hardLightColor = hp_img[...,2]
[x1,y1] = np.where(hardLightColor<0.5)
[x2,y2] = np.where(hardLightColor>=0.5)
for i in range(3):hardLightColor[x1,y1] = hardLightColor[x1,y1]*hardLightColor[x1,y1]*2.0hardLightColor[x2,y2] = 1.0 - (1.0 - hardLightColor[x2,y2]) * (1.0 - hardLightColor[x2,y2]) * 2.0
k = 255.0/(164.0-75.0);
hardLightColor = (hardLightColor - 75.0/255.0) * k
hpss_img = np.zeros((hardLightColor.shape[0],hardLightColor.shape[1],3))
hpss_img[...,0] = hardLightColor
hpss_img[...,1] = hardLightColor
hpss_img[...,2] = hardLightColorhpss_img = np.clip(hpss_img,0,1)  #將所有數據在 0-1 之間#紀錄時間 0.6
timeb = time.time()
print("hpss_img", timeb-timea)# 1111調整亮度 tc_img
# RGB tone curve
# 先利用控制点生成cubic spline曲线
# 参照https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.CubicSpline.html#scipy.interpolate.CubicSpline
x = [0,120.0/255.0,1]
y = [0,146.0/255.0,1]#146
cs = CubicSpline(x,y)
tc_img = cs(input_img) #紀錄時間
timeb = time.time()
print("tc_img", timeb-timea)####  重要  ####
blend_img = input_img * hpss_img  + tc_img *(1-hpss_img)#紀錄時間
timeb = time.time()
print("blend_img", timeb-timea)# sharpen
from PIL import ImageEnhance
enhancer = ImageEnhance.Sharpness(np2pil(blend_img))
img_sharp = enhancer.enhance(2)
result = np.array(img_sharp,np.float32)/255.0#紀錄時間
timeb = time.time()
print("result", timeb-timea)plt.figure(figsize=(16,16))
plt.subplot(121)
plt.imshow(input_img)
plt.axis('off')
plt.subplot(122)
plt.imshow(result)
plt.axis('off')

如何將人臉變漂亮(二)相关推荐

  1. 如何將人臉變漂亮(三)

    利用 mediapipe 進行處理 規劃 1.先把人臉辨識,然後取出框框 2.把框框內的人臉,進行美容 -高反差保留 (1)曝光度調整 (2)綠色與藍色,疊加 (3)YUCIHighPassSkinS ...

  2. 如何將人臉變漂亮(四)

    利用 mediapipe 進行處理 規劃 1.先把人臉辨識,然後取出框框 2.把框框內的人臉,進行美容 -高反差保留 (1)曝光度調整 (2)綠色與藍色,疊加 (3)YUCIHighPassSkinS ...

  3. 如何將人臉變漂亮(六)

    利用 mediapipe 進行處理 規劃 1.先把人臉辨識,然後取出框框 2.把框框內的人臉,進行美容 -高反差保留 (1)曝光度調整 (2)綠色與藍色,疊加 (3)YUCIHighPassSkinS ...

  4. 如何將人臉變漂亮(一)

    利用 mediapipe 進行處理 規劃 1.先把人臉辨識,然後取出框框 2.把框框內的人臉,進行美容 -高反差保留 (1)曝光度調整 (2)綠色與藍色,疊加 (3)YUCIHighPassSkinS ...

  5. 你看到各种各样的漂亮二维码制作都跑不出这8个原理!

    大家常说二维码制作,其实这个二维码制作肯定是借助软件工具的,人徒手并做不来这个东西,人们所说的二维码制作只是对二维码进行加工,让它看起来更漂亮而已,二维码的实际内容并没有什么改变,对人来说制作的二维码 ...

  6. 主管与人相处的十二条准则[转]

    毫无疑问,渊博的学识和不断的创新是事业成功的基础.然而,把一个概念变为成果,离开他人的合作,任何人,无论是伟人还是凡夫,都无法实现. 与人合作得是否愉快且卓有成效,完全取决于你与人相处的能力.以下的准 ...

  7. 【Python】爬虫:微博找人页面爬虫(二)

    [Python]爬虫:微博找人页面爬虫(二) 微博-找人页面,需要登录才行访问,若没有登录就会自动跳转到登录界面, 这时便想到两种方式: 1,使用selenium,自动化模拟登录,但是很不稳定,而且页 ...

  8. 人智导(二十二):规划(下)

    人智导(二十二):规划(下) 部分有序的规划:实例 部分有序(Partial Order)的规划举例 问题:购买milk, banana, drill, 然后回家 SM: 超市(supermarket ...

  9. matlab intergral,matlab學習:人臉識別之HOG(Histograms of Oriented Gradients)

    HOG descriptors 是應用在計算機視覺和圖像處理領域,用於目標檢測的特征描述器.這項技術是用來計算局部圖像梯度的方向信息的統計值.這種方法跟邊緣方向直方圖(edge orientation ...

最新文章

  1. 仅50张图片训练数据的AI分类技术PK​,阿里拿下ECCV 2020竞赛冠军
  2. 权限管理系统之模块管理
  3. 7-4 找到共同的选修课-hebust (10 分)
  4. 虚拟机无法开机数据恢复 (建议在做之前做测试,数据双重备份)
  5. HDU - 1754 I Hate It(Splay-区间最大值)
  6. android手机定位
  7. UVA - 1279 Asteroid Rangers (动点的最小生成树)
  8. mysql_TCL语言(事务)
  9. 禁忌搜索算法c语言代码,禁忌搜索算法CC++源代码.doc
  10. 升级这十点认知,你就是大佬!
  11. 硬件仿真加速器(emulator)
  12. 为报复老东家,程序员编码给自己转账553笔,金额超21万元
  13. python运行黑色窗口怎么弄_selenium+python 去除启动的黑色cmd窗口方法
  14. Azure核心服务(VM)——>创建windows虚拟机并在此之上部署一个cms网站
  15. 设计LDO电路需考虑因素
  16. InnoDB之redo log
  17. BGRABitmap图像操作9c:同时使用莫林杂点和 phong 阴影制作纹理
  18. LTE中RB、RBG、CCE、REG
  19. 【莫烦Python】Matplotlib Python画图教程
  20. 常见html5营销类型有哪些,o2o模式的主要类型有哪些

热门文章

  1. DFT中scan shift/launch/capture过程,launch off shfit/launch from capture OCC
  2. deployer服务器端的配置
  3. React学习之围棋记谱本制作(五)死活判断
  4. ZeroNet正式更名为MicroZero
  5. Spring Cloud Gateway 入门示例
  6. mysql数据什么格式_Mysql数据格式_MySQL
  7. 用代码实现断开Android手机USB连接【转】
  8. Comet OJ - Contest #13【1~5】
  9. zynq ultrascale mpsoc 自定义配置文件解析
  10. Android6.0电池图标外显示电量百分比