主要是借鉴了这个文章,写的非常棒,会比直接使用保边滤波好很多,能够高保真,不会糊掉。
我使用python简单的实现了一下,看起来还不错
import time
import numpy as np
import cv2
def mopi(src):
high_pass = src.copy()
opacity = 50
high_pass = cv2.bilateralFilter(high_pass, 0, 100, 15)
high_pass = high_pass - src + 128
high_pass = cv2.GaussianBlur(high_pass, (3, 3), 0)
dest = (src + 2*high_pass-256)*opacity/100 + src*(100-opacity)/100
return dest
start_time = time.time()
img = cv2.imread('tmp/17.png').astype(np.float32)
out = mopi(img)
print('time: ', time.time() - start_time)
cv2.imwrite('tmp/17_mopi.jpg', out)
效果如下:
运行的速度也很快,在pc上面,能到0.15s
time: 0.15259194374084473
如果想使用,可以稍微调整一些参数就能达到一个不错的效果了