def luminance_only(x, y):
xp = cuda.get_array_module(x)
w = xp.asarray([0.114, 0.587, 0.299], dtype=np.float32)
x_shape = x.shape
y_shape = y.shape
x = x.reshape(x_shape[:2] + (-1,))
xl = xp.zeros((x.shape[0], 1, x.shape[2]), dtype=np.float32)
for i in six.moves.range(len(x)):
xl[i,:] = w.dot(x[i])
xl_mean = xp.mean(xl, axis=2, keepdims=True)
xl_std = xp.std(xl, axis=2, keepdims=True)
y = y.reshape(y_shape[:2] + (-1,))
yl = xp.zeros((y.shape[0], 1, y.shape[2]), dtype=np.float32)
for i in six.moves.range(len(y)):
yl[i,:] = w.dot(y[i])
yl_mean = xp.mean(yl, axis=2, keepdims=True)
yl_std = xp.std(yl, axis=2, keepdims=True)
xl = (xl - xl_mean) / xl_std * yl_std + yl_mean
return xp.repeat(xl, 3, axis=1).reshape(x_shape)
评论列表
文章目录