You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
980 B
27 lines
980 B
3 years ago
|
import cv2
|
||
|
import numpy as np
|
||
|
def Beauty(img):
|
||
|
step = 5
|
||
|
kernel = (32,32) #图片大一点,此处尺寸大一点
|
||
|
|
||
|
img = img/255.0
|
||
|
sz = img.shape[:2]
|
||
|
sz1 = (int(round(sz[1] * step)), int(round(sz[0] * step)))
|
||
|
sz2 = (int(round(kernel[0] * step)), int(round(kernel[0] * step)))
|
||
|
sI = cv2.resize(img, sz1, interpolation=cv2.INTER_LINEAR)
|
||
|
sp = cv2.resize(img, sz1, interpolation=cv2.INTER_LINEAR)
|
||
|
msI = cv2.blur(sI, sz2)
|
||
|
msp = cv2.blur(sp, sz2)
|
||
|
msII = cv2.blur(sI*sI, sz2)
|
||
|
msIp = cv2.blur(sI*sp, sz2)
|
||
|
vsI = msII - msI*msI
|
||
|
csIp = msIp - msI*msp
|
||
|
recA = csIp/(vsI+0.01)
|
||
|
recB = msp - recA*msI
|
||
|
mA = cv2.resize(recA, (sz[1],sz[0]), interpolation=cv2.INTER_LINEAR)
|
||
|
mB = cv2.resize(recB, (sz[1],sz[0]), interpolation=cv2.INTER_LINEAR)
|
||
|
gf = mA*img + mB
|
||
|
gf = gf*255
|
||
|
gf[gf>255] = 255
|
||
|
final = gf.astype(np.uint8)
|
||
|
return final
|