Ich arbeite durch ein Bildverarbeitungsbeispiel in Python 2.7.13. Der Code hat import skimage.morphology as morph
und hat später die Zeile lm1 = morph.is_local_maximum(fimg)
. Ich bekomme die Fehlermeldung:Versuchen, skimage.morphology in einem Bildverarbeitungscode zu verwenden, aber Fehlermeldung
File "2dlocalmaxima.py", line 29, in <module>
lm1 = morph.is_local_maximum(fimg)
AttributeError: 'module' object has no attribute 'is_local_maximum'.
Ich habe dies gegoogelt und habe viele Instanzen dieses Moduls verwendet. Ich kann keine Instanz dafür finden, dass sie veraltet ist. Mache ich etwas falsch? Ich habe versucht, in Python 2.7.13 und 3.6 zu laufen. Beide geben dieselbe Fehlermeldung aus.
Der gesamte Code aus dem Buch:
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')
Welche Version von SciKit-Image verwenden Sie? –
Wie kann ich sagen, welche Version? – jmh
Ich lief "pip install scikit-image" es lief bis zur Fertigstellung, aber die Ergebnisse sind die gleichen. Ich konnte jedoch nicht sagen, welche Version. – jmh