7 Star 22 Fork 4

Gitee 极速下载/FastPhotoStyle

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/NVIDIA/FastPhotoStyle
克隆/下载
photo_gif.py 1.46 KB
一键复制 编辑 原始数据 按行查看 历史
Ming-Yu Liu 提交于 7年前 . Add the tutorial page
"""
Copyright (C) 2018 NVIDIA Corporation. All rights reserved.
Licensed under the CC BY-NC-SA 4.0 license (https://creativecommons.org/licenses/by-nc-sa/4.0/legalcode).
"""
from __future__ import division
from PIL import Image
from torch import nn
import numpy as np
import cv2
from cv2.ximgproc import guidedFilter
class GIFSmoothing(nn.Module):
def forward(self, *input):
pass
def __init__(self, r, eps):
super(GIFSmoothing, self).__init__()
self.r = r
self.eps = eps
def process(self, initImg, contentImg):
return self.process_opencv(initImg, contentImg)
def process_opencv(self, initImg, contentImg):
'''
:param initImg: intermediate output. Either image path or PIL Image
:param contentImg: content image output. Either path or PIL Image
:return: stylized output image. PIL Image
'''
if type(initImg) == str:
init_img = cv2.imread(initImg)
init_img = init_img[2:-2,2:-2,:]
else:
init_img = np.array(initImg)[:, :, ::-1].copy()
if type(contentImg) == str:
cont_img = cv2.imread(contentImg)
else:
cont_img = np.array(contentImg)[:, :, ::-1].copy()
output_img = guidedFilter(guide=cont_img, src=init_img, radius=self.r, eps=self.eps)
output_img = cv2.cvtColor(output_img, cv2.COLOR_BGR2RGB)
output_img = Image.fromarray(output_img)
return output_img
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/mirrors/FastPhotoStyle.git
git@gitee.com:mirrors/FastPhotoStyle.git
mirrors
FastPhotoStyle
FastPhotoStyle
master

搜索帮助