pytorch 膨胀算法实现大眼效果

作者:watersink 时间:2022-10-25 18:19:51 

论文:Interactive Image Warping(1993年Andreas Gustafsson)

算法思路:

pytorch 膨胀算法实现大眼效果

以眼睛中心为中心点,对眼睛区域向外放大,就实现了大眼的效果。大眼的基本公式如下,

pytorch 膨胀算法实现大眼效果

假设眼睛中心点为O(x,y),大眼区域半径为Radius,当前点位为A(x1,y1),对其进行改进,加入大眼程度控制变量Intensity,其中Intensity的取值范围为0~100。 

pytorch 膨胀算法实现大眼效果

其中,dis表示AO的欧式距离,k表示缩放比例因子,k0表示大眼程度,xd,yd表示A点经过大眼变换后的目标点B的坐标。

当k=0时,目标点B与O点重合。

当k=1时,目标点B与A点重合。

当k<1.0时,目标点B的计算函数单调递增,眼睛放大。

当k>1.0时,目标点B的计算函数单调递减,眼睛缩小。

人眼半径求法,

pytorch 膨胀算法实现大眼效果

根据眼睛左右2个关键点来计算大眼区域所在的半径Radius 

pytorch 膨胀算法实现大眼效果

大眼程度Intensity求法,

根据图像分辨率,结合实际经验来计算大眼程度Intensity。

比如Intensity = 15*512*512/(width*height)

应用场景:

适用于任何球形局部形变的场景,比如大眼,比如嘴唇微笑。

代码实现:


import cv2
import math
import numpy as np

def big_eye_adjust_fast(src, PointX, PointY, Radius, Strength):
   processed_image = np.zeros(src.shape, np.uint8)
   processed_image = src.copy()
   height = src.shape[0]
   width = src.shape[1]
   PowRadius = Radius * Radius

maskImg = np.zeros(src.shape[:2], np.uint8)
   cv2.circle(maskImg, (PointX, PointY), math.ceil(Radius), (255, 255, 255), -1)

mapX = np.vstack([np.arange(width).astype(np.float32).reshape(1, -1)] * height)
   mapY = np.hstack([np.arange(height).astype(np.float32).reshape(-1, 1)] * width)

OffsetX = mapX - PointX
   OffsetY = mapY - PointY
   XY = OffsetX * OffsetX + OffsetY * OffsetY

ScaleFactor = 1 - XY / PowRadius
   ScaleFactor = 1 - Strength / 100 * ScaleFactor
   UX = OffsetX * ScaleFactor + PointX
   UY = OffsetY * ScaleFactor + PointY
   UX[UX < 0] = 0
   UX[UX >= width] = width - 1
   UY[UY < 0] = 0
   UY[UY >= height] = height - 1

np.copyto(UX, mapX, where=maskImg == 0)
   np.copyto(UY, mapY, where=maskImg == 0)

UX = UX.astype(np.float32)
   UY = UY.astype(np.float32)

processed_image = cv2.remap(src, UX, UY, interpolation=cv2.INTER_LINEAR)

return processed_image

image = cv2.imread("tests/images/klst.jpeg")
processed_image = image.copy()
PointX_left, PointY_left, Radius_left, Strength_left = 150, 190, 44, 19.78
PointX_right, PointY_right, Radius_right, Strength_right = 244, 194, 42, 19.78
processed_image = big_eye_adjust_fast(processed_image, PointX_left, PointY_left, Radius_left, Strength_left)
processed_image = big_eye_adjust_fast(processed_image, PointX_right, PointY_right, Radius_right, Strength_right)
cv2.imwrite("big.jpg", processed_image)

实验效果: 

pytorch 膨胀算法实现大眼效果

来源:https://blog.csdn.net/qq_14845119/article/details/121516646

标签:pytorch,膨胀算法,大眼
0
投稿

猜你喜欢

  • python-序列解包(对可迭代元素的快速取值方法)

    2023-12-28 23:23:57
  • 从源码解析Python的Flask框架中request对象的用法

    2021-02-20 02:15:57
  • MySQL触发器基本用法详解【创建、查看、删除等】

    2024-01-14 09:48:22
  • 利用JavaScript正则表达式模拟Google Talk的文本处理

    2007-12-04 18:43:00
  • python+openCV利用摄像头实现人员活动检测

    2021-06-23 10:39:36
  • python em算法的实现

    2021-09-18 11:45:30
  • 对tf.reduce_sum tensorflow维度上的操作详解

    2023-01-07 14:10:28
  • layDate插件设置开始和结束时间

    2024-05-03 15:05:03
  • asp.net连接数据库 增加,修改,删除,查询代码

    2024-01-20 15:52:31
  • 利用不同样式改变相同xhtml结构的布局

    2008-08-20 18:17:00
  • MySQL数据库JDBC编程详解流程

    2024-01-15 09:39:55
  • 查看Django和flask版本的方法

    2021-01-29 02:50:11
  • 深入理解Django中内置的用户认证

    2022-01-25 10:05:43
  • Git基础学习之tag标签操作详解

    2023-01-01 08:27:20
  • Oracle 数据表分区的策略

    2010-07-21 13:30:00
  • python编程实现12306的一个小爬虫实例

    2021-09-23 10:58:14
  • 站长如何活用"nofollow"标签

    2008-05-13 12:40:00
  • python 百度aip实现文字识别的实现示例

    2023-12-15 19:53:47
  • .NET 2.0 的压缩功能代码

    2023-07-14 05:25:22
  • Linux下Python脚本自启动和定时启动的详细步骤

    2022-08-13 20:51:22
  • asp之家 网络编程 m.aspxhome.com