最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

pytorch?膨脹算法實現(xiàn)大眼效果

 更新時間:2021年11月26日 08:41:38   作者:watersink  
在PS中,我們可以利用液化工具對人像進行瘦臉、放大眼睛等系列的常規(guī)操作。今天我們來了解一下這些操作的算法原理,并用pytorch?膨脹算法來實現(xiàn)大眼效果,感興趣的可以了解一下

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

算法思路:

以眼睛中心為中心點,對眼睛區(qū)域向外放大,就實現(xiàn)了大眼的效果。大眼的基本公式如下,

假設(shè)眼睛中心點為O(x,y),大眼區(qū)域半徑為Radius,當前點位為A(x1,y1),對其進行改進,加入大眼程度控制變量Intensity,其中Intensity的取值范圍為0~100。?

其中,dis表示AO的歐式距離,k表示縮放比例因子,k0表示大眼程度,xd,yd表示A點經(jīng)過大眼變換后的目標點B的坐標。

當k=0時,目標點B與O點重合。

當k=1時,目標點B與A點重合。

當k<1.0時,目標點B的計算函數(shù)單調(diào)遞增,眼睛放大。

當k>1.0時,目標點B的計算函數(shù)單調(diào)遞減,眼睛縮小。

人眼半徑求法,

根據(jù)眼睛左右2個關(guān)鍵點來計算大眼區(qū)域所在的半徑Radius?

大眼程度Intensity求法,

根據(jù)圖像分辨率,結(jié)合實際經(jīng)驗來計算大眼程度Intensity。

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

應(yīng)用場景:

適用于任何球形局部形變的場景,比如大眼,比如嘴唇微笑。

代碼實現(xiàn):

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)

實驗效果:?

到此這篇關(guān)于pytorch 膨脹算法實現(xiàn)大臉效果的文章就介紹到這了,更多相關(guān)pytorch 膨脹算法內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論

澄城县| 高尔夫| 许昌县| 遵义市| 乐昌市| 靖边县| 永善县| 公安县| 治县。| 偏关县| 南郑县| 井冈山市| 满洲里市| 衡山县| 治县。| 白玉县| 阜城县| 神农架林区| 积石山| 东兴市| 涞源县| 呼图壁县| 内江市| 彝良县| 枣强县| 赤峰市| 运城市| 安远县| 开封县| 连城县| 鄂托克前旗| 麻城市| 小金县| 望城县| 化德县| 静乐县| 三江| 乌兰浩特市| 漠河县| 三台县| 定安县|