Color-Mood Transformation

Color-Mood Transformation

参考文献:Data-Driven Image Color Theme Enhancement

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[(L50)2+(a3)2+(b171.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(100L)+0.45cos(h100) 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(h50) h e a t = − 0.5 + 0.02 ( C ∗ ) 1.07 cos ⁡ ( h − 50 ∘ )

其中 L L ∗ 是CIELAB的亮度, C=a2+b2 C ∗ = a ∗ 2 + b ∗ 2 是CIELAB的色度, h=arctan(ba) h = arctan ⁡ ( b ∗ a ∗ ) 是CIELAB的色相角, a,b a ∗ , b ∗ 是CIELAB的坐标。

  然后颜色主题和图片的相似度通过下面的能量方程衡量:
  
E=1NNt=1F(ct)1mmk=1F(ck)2 E = ‖ 1 N ∑ t = 1 N F ( c t → ) − 1 m ∑ k = 1 m F ( c k ∗ → ) ‖ 2

其中 ct c t → 为图像中的像素点, N N 为图片包含的像素点总数,ck为颜色主题中的颜色, 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

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Maples丶丶

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值