在哪个位置使用from skimage.morphology import FilterProgressiveMorphological导入 'FilterProgressiveMorphological' 模块:
时间: 2023-04-06 18:02:07 浏览: 62
您可以在 Python 代码中的开头使用以下语句导入 'FilterProgressiveMorphological' 模块:from skimage.morphology import FilterProgressiveMorphological。
相关问题
如何使用from skimage.morphology import FilterProgressiveMorphological导入 'FilterProgressiveMorphological' 模块:
您可以使用以下代码导入 'FilterProgressiveMorphological' 模块:
from skimage.morphology import FilterProgressiveMorphological
AttributeError: module 'skimage.morphology' has no attribute 'binary_hit_or_miss'
抱歉,看来最新版本的scikit-image库已经移除了binary_hit_or_miss函数。可以使用其他函数替代来实现同样的效果。比如,可以使用scikit-image库的match_template函数来实现同样的效果。代码如下:
```
from skimage.morphology import skeletonize
from skimage.filters import threshold_otsu
from skimage.feature import match_template
import numpy as np
BO_skel = skeletonize(BO) # BO为二值化图像
BO_hb = np.zeros_like(BO_skel)
template = np.array([[0, 0, 0], [0, 1, 0], [1, 1, 1]]) # hbreak模板
thresh = threshold_otsu(BO_skel)
for i in range(BO_skel.shape[0] - 2):
for j in range(BO_skel.shape[1] - 2):
if BO_skel[i, j] == 1:
roi = BO_skel[i:i+3, j:j+3]
if np.all(roi == template):
corr = match_template(BO_skel[i-5:i+8, j-5:j+8], template)
if np.max(corr) > 0.9 and BO_skel[i, j] > thresh:
BO_hb[i+1, j+1] = 1
```
这个代码中,我们首先使用skeletonize函数得到了二值化图像BO的骨架图BO_skel。然后我们定义了hbreak模板,并使用match_template函数在图像的每一个像素位置上匹配这个模板。如果匹配得分比较高,就判断这个像素是一个端点,并将对应位置的BO_hb标记为1。需要注意的是,在判断像素是否是端点时,我们使用了OTSU阈值法来确定一个合适的阈值。