尝试在图像处理代码中使用Skimage.Morphology,但获取错误消息



我正在通过python 2.7.13中的图像处理示例进行工作。代码有 import skimage.morphology as morph,然后具有lm1 = morph.is_local_maximum(fimg)行。我收到错误消息:

File "2dlocalmaxima.py", line 29, in <module>
    lm1 = morph.is_local_maximum(fimg)
AttributeError: 'module' object has no attribute 'is_local_maximum'.

我已经搜索了此内容,并发现了使用此模块的许多实例。我找不到弃用的实例。难道我做错了什么?我尝试在Python 2.7.13和3.6中跑步。两者都提供相同的错误消息。

本书的总代码是:

import numpy as np
import matplotlib.pyplot as mpl 
import scipy.ndimage as ndimage 
import skimage.morphology as morph
# Generating data points with a non-uniform background
x = np.random.uniform(low=0, high=200, size=20).astype(int) 
y = np.random.uniform(low=0, high=400, size=20).astype(int)
# Creating image with non-uniform background 
func = lambda x, y: np.cos(x)+ np.sin(y) 
grid_x, grid_y = np.mgrid[0:12:200j, 0:24:400j] 
bkg = func(grid_x, grid_y)
bkg = bkg / np.max(bkg)
# Creating points
clean = np.zeros((200,400))
clean[(x,y)] += 5
clean = ndimage.gaussian_filter(clean, 3) 
clean = clean / np.max(clean)
# Combining both the non-uniform background 
# and points
fimg = bkg + clean
fimg = fimg / np.max(fimg)
# Calculating local maxima 
lm1 = morph.is_local_maximum(fimg)
x1, y1 = np.where(lm1.T == True)
# Creating figure to show local maximum detection 
# rate success
fig = mpl.figure(figsize=(8, 4))
ax = fig.add_subplot(111)
ax.imshow(fimg)
ax.scatter(x1, y1, s=100, facecolor='none', edgecolor='#009999') 
ax.set_xlim(0,400)
ax.set_ylim(0,200)
ax.xaxis.set_visible(False)
ax.yaxis.set_visible(False)
fig.savefig('scikit_image_f02.pdf', bbox_inches='tight')

通过不同的文件搜索后,我确定模块is_local_maximum的名称更改为 local_maxima。我的代码运行完成,并在进行替换时产生了预期的结果。

最新更新