ImportError: cannot import name 'disk' from 'skimage.draw'

3.5k Views Asked by At

**

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:

It will be really helpful for me if anyone can help me.I have tried to install skimage multiple of time I have installed it and uninstalled it but I couldn't able to find any solution to it.I have also imported all the libraries required but I don't know what is the issue . Please provide me accurate result for the code. Thank you in advance. Below is my error :
**

**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

There are 1 best solutions below

0
phispi On

It seems you missed to import the function. I assume it needs something like

from skimage.feature import corner_peaks

at the beginning. (Your indentation in the example above is wrong by the way but I assume that is a copy/paste error.)

Later in the script you will encounter the error that plt is not defined. You'd need to

import matplotlib.pyplot as plt