Color-Mood Transformation
Color-Mood 颜色空间由activity,weight和heat三个坐标轴组成。CIELAB空间可以通过经验公式转为Color-Mood空间。
对于Lab空间的一点
,Color-Mood空间中相应的点
,其中
由下面三个公式定义:
其中 是CIELAB的亮度, 是CIELAB的色度, 是CIELAB的色相角, 是CIELAB的坐标。
然后颜色主题和图片的相似度通过下面的能量方程衡量:
其中 为图像中的像素点, 为图片包含的像素点总数, 为颜色主题中的颜色, 为颜色主题的数量。
下面附上Tensorflow的实现代码,image_lab
是没有进行过归一化的lab空间图像:
def lab_to_mood(image_lab):
assert image_lab.get_shape()[-1] == 3
n, h, w, c = image_lab.get_shape().as_list()
eps = 1e-5
lab_pixels = image_lab # 变量名强迫症
L = tf.reshape(lab_pixels[:, :, :, 0], [n, h, w, 1])
a = tf.reshape(lab_pixels[:, :, :, 1], [n, h, w, 1])
b = tf.reshape(lab_pixels[:, :, :, 2], [n, h, w, 1])
C = tf.sqrt(a**2 + b**2)
h = tf.atan(b / (a + eps)) * 180 / 3.1415926 # 弧度转角度
activity = -2.1 + 0.06 * tf.sqrt((L - 50.)**2 + (a - 3.)**2 + ((b - 1.7)/1.4)**2)
weight = -1.8 + 0.04 * (100 - L) + 0.45 * tf.cos((h - 100) * 3.1419526 / 180)
heat = -0.5 + 0.02 * C**1.07 * tf.cos((h - 50) * 3.1419526 / 180)
mood = tf.concat([activity, weight, heat], axis=3)
return mood
ps:一开始把这个放到loss函数里面,一直出现Nan的情况,找了好久的原因……下次出现Nan的情况首先要检查分母啊!!!!!!调了1、2个小时,一直找不到错误的位置,差点去研究reduce_mean的源码了,记住教训!凡是带分母的都加个eps