我有一段python代码,旨在提取字母并标记包含图像的每个区域。 我正在使用Google Colab
我收到以下错误:
NameError跟踪(最近一次通话最后一次)
在()中 1
----> 2 image = imageio.imread('https://pbs.twimg.com/profile_images/985792111713947648/7YD1ZYpe_400x400.jpg') 3 4 5
NameError:未定义名称'imageio'```
此处显示完整代码:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
from scipy.misc import imageio.imread,imresize
from skimage.segmentation import clear_border
from skimage.morphology import label
from skimage.measure import regionprops
image = imageio.imread('https://pbs.twimg.com/profile_images/985792111713947648/7YD1ZYpe_400x400.jpg')
#apply threshold in order to make the image binary
bw = image < 120
# remove artifacts connected to image border
cleared = bw.copy()
clear_border(cleared)
# label image regions
label_image = label(cleared,neighbors=8)
borders = np.logical_xor(bw, cleared)
label_image[borders] = -1
print(label_image.max())
fig, ax = plt.subplots(ncols=1, nrows=1, figsize=(6, 6))
ax.imshow(bw, cmap='jet')
答案 0 :(得分:0)
您正在使用尚未导入的软件包中的函数。首先,您需要在系统中安装imageio(pip install imageio),然后将其包含在代码中(并删除其他未读内容)。新代码将为:
import imageio
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
from skimage.segmentation import clear_border
from skimage.morphology import label
如果要使用imresize,则需要安装枕头。