# 瘦脸之液化算法

1. 圆内所有像素均沿着变形向量的方向发生偏移
2. 距离圆心越近，变形程度越大
3. 距离圆周越近，变形程度越小，当像素点位于圆周时，该像素不变形
4. 圆外像素不发生偏移

1. 局部变形算法，只能基于一个中心点，向另外一个点的方向啦。如果想多个点一起拉伸，只能每个点分别做一次液化，通过针对多个部位多次液化来实现。
2. 单点拉伸的变形，可以实现瘦脸的效果，但是效果自然度有待提升。

``````import cv2
import math
import numpy as np

def localTranslationWarpFastWithStrength(srcImg, startX, startY, endX, endY, radius, strength):
copyImg = np.zeros(srcImg.shape, np.uint8)
copyImg = srcImg.copy()

K0 = 100/strength

# 计算公式中的|m-c|^2
ddmc_x = (endX - startX) * (endX - startX)
ddmc_y = (endY - startY) * (endY - startY)
H, W, C = srcImg.shape

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

distance_x = (mapX - startX) * (mapX - startX)
distance_y = (mapY - startY) * (mapY - startY)
distance = distance_x + distance_y
K1 = np.sqrt(distance)
ratio_x = (ddradius - distance_x) / (ddradius - distance_x + K0 * ddmc_x)
ratio_y = (ddradius - distance_y) / (ddradius - distance_y + K0 * ddmc_y)
ratio_x = ratio_x * ratio_x
ratio_y = ratio_y * ratio_y

UX = mapX - ratio_x * (endX - startX) * (1 - K1/radius)
UY = mapY - ratio_y * (endY - startY) * (1 - K1/radius)

UX = UX.astype(np.float32)
UY = UY.astype(np.float32)
copyImg = cv2.remap(srcImg, UX, UY, interpolation=cv2.INTER_LINEAR)

return copyImg

processed_image = image.copy()
startX_left, startY_left, endX_left, endY_left = 101, 266, 192, 233
startX_right, startY_right, endX_right, endY_right = 287, 275, 192, 233