Color-Mood Transformation
Color-Mood 颜色空间由activity,weight和heat三个坐标轴组成。CIELAB空间可以通过经验公式转为Color-Mood空间。
对于Lab空间的一点
c⃗ =(L∗,a∗,b∗)
c
→
=
(
L
∗
,
a
∗
,
b
∗
)
,Color-Mood空间中相应的点
e⃗ =F(c⃗ )
e
→
=
F
(
c
→
)
,其中
F
F
由下面三个公式定义:
activity=−2.1+0.06[(L∗−50)2+(a∗−3)2+(b∗−171.4)2]12
a
c
t
i
v
i
t
y
=
−
2.1
+
0.06
[
(
L
∗
−
50
)
2
+
(
a
∗
−
3
)
2
+
(
b
∗
−
17
1.4
)
2
]
1
2
weight=−1/8+0.04(100−L∗)+0.45cos(h−100∘) w e i g h t = − 1 / 8 + 0.04 ( 100 − L ∗ ) + 0.45 cos ( h − 100 ∘ )
heat=−0.5+0.02(C∗)1.07cos(h−50∘) h e a t = − 0.5 + 0.02 ( C ∗ ) 1.07 cos ( h − 50 ∘ )
其中 L∗ L ∗ 是CIELAB的亮度, C∗=a∗2+b∗2−−−−−−−√ C ∗ = a ∗ 2 + b ∗ 2 是CIELAB的色度, h=arctan(b∗a∗) h = arctan ( b ∗ a ∗ ) 是CIELAB的色相角, a∗,b∗ a ∗ , b ∗ 是CIELAB的坐标。
然后颜色主题和图片的相似度通过下面的能量方程衡量:
E=∥1N∑Nt=1F(ct→)−1m∑mk=1F(c∗k→)∥2
E
=
‖
1
N
∑
t
=
1
N
F
(
c
t
→
)
−
1
m
∑
k
=
1
m
F
(
c
k
∗
→
)
‖
2
其中 ct→ c t → 为图像中的像素点, N N 为图片包含的像素点总数,为颜色主题中的颜色, m m <script type="math/tex" id="MathJax-Element-465">m</script>为颜色主题的数量。
下面附上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