一、環境:Win10+Pycharm+TensorFlow(1.15)+Python3.6
二、示例代碼
基於訓練模型,加載以及預處理圖像如下:
def load_image(path):
img = imread(path)
# crop image from center
short_edge = min(img.shape[:2])
yy = int((img.shape[0] - short_edge) / 2)
xx = int((img.shape[1] - short_edge) / 2)
crop_img = img[yy : yy + short_edge, xx : xx + short_edge]
# resize img to (224,224)
img = skimage.transform.resize(crop_img, (224, 224))
# desaturate image
return (img[:,:,0] + img[:,:,1] + img[:,:,2]) / 3.0
三、測試效果
由於項目需要,基於TensorFlow實現灰度圖着色,看了一些相關的開源代碼並進行測試,上色效果還可以,測試效果如下所示:
原圖:
着色效果圖如下:
模型下載
提取碼:eu51
整體着色效果還可以。