Colorization的数据准备

  • 数据准备:彩色----->灰色
  • 上色目标:灰色----->彩色
In [1]:
import os
import sys
import cv2
import numpy as np
import IPython

#-------------------------------------------------------------------
def imshow(img):
    _,ret = cv2.imencode('.jpg', img)
    i = IPython.display.Image(data=ret)
    IPython.display.display(i)

#-------------------------------------------------------------------
width  = 400
height = 300
channel=3
filename = "../test/images/lotus.jpg"
img = cv2.imread(filename)
# img = cv2.resize(img,(width,height))
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
gray = np.dstack((gray,gray,gray))
# print(img.shape)
# print(gray.shape)
images = np.hstack((gray,img))
imshow(images)
  • 上色数据:anime
  • 数据准备:根据图片尺寸将数据的sketch和colored分开,在 load data 时将 训练数据设为:sketch , 标签设为:colored。
In [3]:
filename = "../test/images/anime.png"
# filename = "../test/images/seg.jpg"
img = cv2.imread(filename)
# w = int(img.shape[1]/2)
w = img.shape[1] >> 1
colored = img[:,:w,:]
sketch  = img[:,w:,:]
images  = np.hstack((sketch,colored))
imshow(images)