【问题标题】:sRGB gamma curve implement in tensorflowsRGB伽玛曲线在张量流中实现
【发布时间】:2019-03-20 21:27:46
【问题描述】:

我需要在 tensorflow 中实现 sRGB 伽马曲线。但我无法计算张量流中的元素明智条件。

在sRGB曲线中,如果值小于等于0.0031308,则为线性运算:x*12.95 如果该值大于 0.0031308,则为伽马校正: 1.055*x^(1/2.4) - 0.055

我尝试使用 tf.cond(image > 0.0031308, function1, function2) 但它返回错误。如果有人可以帮助我,我将不胜感激!!!

【问题讨论】:

  • 您可以使用x^(1/2.2) 非常接近它,而无需任何条件。

标签: python tensorflow gamma srgb


【解决方案1】:

也许你需要tf.where()tf.greater()。例如:

import tensorflow as tf
import numpy as np

image = np.random.random_sample(size=(2,3,3,1))/100
print(image)

image_tf = tf.placeholder(shape=(None,3,3,1),dtype=tf.float32)

new_image = tf.where(tf.greater(image_tf,0.0031308)
                     ,1.055*tf.pow(image_tf,1/2.4) - 0.055
                     ,image_tf*12.95)

with tf.Session() as sess:
    print(sess.run(new_image,feed_dict={image_tf:image}))
# image
[[[[0.0048715 ]
   [0.00472688]
   [0.00138391]]

  [[0.00848472]
   [0.00055767]
   [0.00835372]]

  [[0.00872362]
   [0.00390934]
   [0.00795842]]]


 [[[0.00756143]
   [0.00494474]
   [0.00201968]]

  [[0.00350234]
   [0.0056558 ]
   [0.00602147]]

  [[0.00692543]
   [0.0045199 ]
   [0.00012196]]]]
# new image
[[[[0.05975685]
   [0.05832487]
   [0.01792167]]

  [[0.08960549]
   [0.0072218 ]
   [0.08867098]]

  [[0.09128823]
   [0.04970375]
   [0.08579818]]]


 [[[0.08282798]
   [0.06047264]
   [0.02615486]]

  [[0.04501574]
   [0.06712133]
   [0.07035124]]

  [[0.07787357]
   [0.05623017]
   [0.00157937]]]]

【讨论】:

    猜你喜欢
    • 2014-03-01
    • 2022-12-10
    • 2012-01-31
    • 2021-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多