ValueError: Parameters "fully_connected" must be either "high" or "low".
时间: 2023-07-08 11:51:54 浏览: 46
非常抱歉,我之前的回答中 `fully_connected` 参数的取值有误。在 `skimage.measure.find_contours` 函数中,`fully_connected` 参数应该是 `"high"` 或者 `"low"`,分别对应着 8 连通和 4 连通。因此,正确的 Python 代码应该是这样的:
```python
from skimage.measure import find_contours
# BO_hb 是二值图像
contours = find_contours(BO_hb, 0.5, connectivity=4)
# B 是包含所有边界点坐标的列表
B = [contour[:, ::-1] - 0.5 for contour in contours]
```
这里使用 `connectivity=4` 指定了 4 连通,得到的结果与 MATLAB 中的 `bwboundaries` 函数使用 `"noholes"` 参数的效果是相同的。
相关问题
File "D:\Programming\envs\env_pytorch\Lib\site-packages\skimage\measure\_find_contours.py", line 128, in find_contours raise ValueError('Parameters "fully_connected" must be either ' ValueError: Parameters "fully_connected" must be either "high" or "low".
根据错误提示,`ValueError: Parameters "fully_connected" must be either "high" or "low"`,意味着在 `measure.find_contours` 函数中,`fully_connected` 参数只能设置为字符串 `"high"` 或 `"low"`。这是因为 `fully_connected` 参数在 `skimage` 1.0 版本中发生了变化,只能接受字符串参数 `"high"` 或 `"low"`,表示使用不同的连接方式。
例如,要使用 `"high"` 连接方式,可以这样调用 `measure.find_contours` 函数:
``` python
import numpy as np
from skimage import measure
# 创建一个 10 x 10 的二维矩阵
image = np.zeros((10, 10))
# 在矩阵上绘制一个三角形
image[2:8, 2:8] = np.tri(6, 6)
# 查找轮廓
contours = measure.find_contours(image, 0.5, fully_connected="high")
# 输出轮廓数量
print(len(contours)) # 2
```
注意,在 `skimage` 1.0 版本之前,`fully_connected` 参数可以设置为布尔值 `True` 或 `False`,表示使用 4-连接或 8-连接。如果你使用的是旧版本的 `skimage`,可以将 `fully_connected` 设置为布尔值。但是,建议使用最新版本的 `skimage` 并使用字符串 `"high"` 或 `"low"` 来设置 `fully_connected` 参数。
ValueError: name for name_scope must be a string.
This error occurs when a non-string value is passed as the argument for the `name` parameter in a `name_scope` function in TensorFlow. The `name` parameter is used to define a name scope for the operations inside it, and it must be a string.
To resolve this error, ensure that the value passed for the `name` parameter is a string. If you are passing a variable or an object, convert it to a string before passing it. For example:
```
import tensorflow as tf
# define a variable
var = tf.Variable(0, name='my_var')
# create a name scope with a string name
with tf.name_scope('my_scope'):
# operations inside the name scope
var_1 = tf.add(var, 1, name='var_add')
```
In the example above, the `name` parameter is passed as a string to the `tf.name_scope` function, and the operations inside it use string names for their variables. This ensures that the TensorFlow graph is constructed properly and can be executed without errors.