首页 > 解决方案 > 我只需要等效于 cv2.threshold nad np.std 的 tensorflow 函数即可在 tensorflow 1.8 中使用

问题描述

 I need to convert the following line into its tensorflow equivalent in tf version 1.8
 but I am not getting the appropriate functions equivalent to cv2.threshold and np.std in TF  1.8

 ret,mask = cv2.threshold(mask,tf.reduce_mean(mask)+1.2*np.std(mask),255,cv2.THRESH_BINARY)

该行的输出应该是二进制掩码

标签: tensorflow

解决方案


你可以这样做:

thr = tf.math.reduce_mean(mask) + 1.2 * tf.math.reduce_std(mask)
mask = tf.cast(mask > thr, tf.uint8) * 255

推荐阅读