导入错误:无法从“skimage.draw”

时间:2021-03-25 20:10:29

标签: python numpy scipy gaussian corner-detection

**

I am new to the python interface. I am importing the numpy, scipy , gradient descend libraries . And By using the skimage I am importing imread and rgb2gray .By using the scipy library I am using the signal function .With gradient descent I am converting the image into imgray .Then I am applying the gaussian filter and when I am mapping corner function using harris response function I am getting the error:

如果有人可以帮助我,这对我真的很有帮助。我已经多次尝试安装 skimage 我已经安装并卸载了它,但我找不到任何解决方案。我也导入了所有需要的库,但我不知道是什么问题。请为我提供代码的准确结果。先感谢您。 以下是我的错误:
**

**NameError                                 Traceback (most recent call last)
<ipython-input-7-76c3bdecb24d> in <module>
----> 1 corners = corner_peaks(harris_response)
      2 fig, ax = plt.subplots()
      3 ax.imshow(img, interpolation='nearest', cmap=plt.cm.gray)
      4 ax.plot(corners[:, 1], corners[:, 0], '.r', markersize=3)

NameError: name 'corner_peaks' is not defined**




Below is my code :

    from skimage.io import imread
    from skimage.color import rgb2gray
    img = imread('box.jpg')
    imggray = rgb2gray(img)
        
    from scipy import signal as sig
    import numpy as np
    def gradient_x(imggray):
         ##Sobel operator kernels.
         kernel_x = np.array([[-1, 0, 1],[-2, 0, 2],[-1, 0, 1]])
         return sig.convolve2d(imggray, kernel_x, mode='same')
    def gradient_y(imggray):
         kernel_y = np.array([[1, 2, 1], [0, 0, 0], [-1, -2, -1]])
    return sig.convolve2d(imggray, kernel_y, mode='same')
    I_x = gradient_x(imggray)
    I_y = gradient_y(imggray)
        
    from scipy.ndimage import gaussian_filter
        
    Ixx = gaussian_filter(I_x**2, sigma=1)
    Ixy = gaussian_filter(I_y*I_x, sigma=1)
    Iyy = gaussian_filter(I_y**2, sigma=1)
        
    k = 0.05
    # determinant
    detA = Ixx * Iyy - Ixy ** 2
    # trace
    traceA = Ixx + Iyy
         
    harris_response = detA - k * traceA ** 2
        
    img_copy_for_corners = np.copy(img)
    img_copy_for_edges = np.copy(img)
    for rowindex, response in enumerate(harris_response):
         for colindex, r in enumerate(response):
             if r > 0:
           # this is a corner
                 img_copy_for_corners[rowindex, colindex] = [255,0,0]
             elif r < 0:
           # this is an edge
                 img_copy_for_edges[rowindex, colindex] = [0,255,0]
        
    corners = corner_peaks(harris_response)
    fig, ax = plt.subplots()
    ax.imshow(img, interpolation='nearest', cmap=plt.cm.gray)
    ax.plot(corners[:, 1], corners[:, 0], '.r', markersize=3)

1 个答案:

答案 0 :(得分:0)

您似乎错过了导入功能。我认为它需要像

from skimage.feature import corner_peaks

开头。 (顺便说一下,您在上面示例中的缩进是错误的,但我认为这是复制/粘贴错误。)

稍后在脚本中您将遇到 plt 未定义的错误。你需要

import matplotlib.pyplot as plt
相关问题