pythonimage-processingcorner-detection

'function' object has no attribute 'flat'


I'm trying to perform corner-detection on some images in Python.

I first perform the shi-tomasi algorithm with the following code:

def corners_map(image):
    # Convert to grayscale and convert the image to float
    RGB = img_as_float(color.rgb2gray(image))

    # Apply shi-tomasi algorithm
    corners_map = feature.corner_shi_tomasi(RGB, 10)

    # Plot results
    plt.figure(figsize=(12,6))
    plt.subplot(121)
    plt.imshow(RGB, cmap=cm.gist_gray)
    plt.title('Original image')
    plt.subplot(122)
    plt.imshow(corners_map, cmap=cm.jet)
    plt.colorbar(orientation='horizontal')
    plt.title('Corners map');

Then I apply the feature.corner_peaks from skimage but when I call the function, it gives me an error "AttributeError: 'function' object has no attribute 'flat'". Below is the code:

def corner_peaks(image):
    # Apply corner peak detection algorithm
    corners = feature.corner_peaks(corners_map)

    #Plot results
    plt.figure(figsize=(12,6))
    plt.subplot(121)
    plt.imshow(RGB, cmap=cm.gist_gray)
    plt.title('Original image')
    plt.figure(figsize=(12,6))
    plt.subplot(122)
    plt.imshow(RGBimg, cmap=cm.gist_gray)
    plt.scatter(corners[:,1], corners[:,0], s=30)
    plt.title('skimage.feature.corner_peaks result')

    corner_peaks(image1)

I'm still not too fluent in Python, so any help to fix this problem is greatly appreciated.

This is the full error:

Error


Solution

  • You have reused the name corners_map for an image and also for a function. Since functions are first-class in python, you can pass them as function arguments. On this line corners = feature.corner_peaks(corners_map), the corners_map you are referencing is the above defined function. Just rename the function, the image, or both.