tensorflow - 我只需要等效于 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)
该行的输出应该是二进制掩码
解决方案
你可以这样做:
thr = tf.math.reduce_mean(mask) + 1.2 * tf.math.reduce_std(mask)
mask = tf.cast(mask > thr, tf.uint8) * 255
推荐阅读
- asp.net - .NET Core:如何发送到 /Account/Login 而不是 /Identity/Account/Login
- c++ - 为什么我无法在 MSVS2019 / C++ 中获取 char 或 uint8_t 变量的内存地址?
- node.js - 如何不使用 node_modules 文件夹?
- javascript - Javascript代码在php文件中不起作用
- python - discord.py-rewrite - 使用 PyQt5 的动态 Web 抓取无法正常工作
- scala - 给出 spark-shell 参数
- python - Python。如何比较两个文本,不包括比较中的某些块
- javascript - 在 Google 表格的 JavaScript 中推送时无法初始化数组值
- c# - 使用 TextBox 中的数据并与以前的数据进行比较
- python - Homebrew 将 Python 3.7.x 降级到 3.7.3