CNTK/GeneralizedHoughTransform/generalized_ht.py
def general_hough(gh, reference_image, query):
    '''
    Uses a GH closure to detect shapes in an image and create nice output
    '''
    query_image = imread(query, flatten=True)
    query_image = imresize(query_image, 0.25)
    accumulator = gh(query_image)

    plt.clf()
    plt.gray()

    fig = plt.figure()
    fig.add_subplot(2,2,1)
    plt.title('Reference image')
    plt.imshow(reference_image)

    fig.add_subplot(2,2,2)
    plt.title('Query image')
    plt.imshow(query_image)

    fig.add_subplot(2,2,3)
    plt.title('Accumulator')
    plt.imshow(accumulator)

    fig.add_subplot(2,2,4)
    plt.title('Detection')
    plt.imshow(query_image)

    # top 5 results in red
    m = n_max(accumulator, 5)
    y_points = [pt[1][0] for pt in m]
    x_points = [pt[1][1] for pt in m]
    plt.scatter(x_points, y_points, marker='o', color='r')

    # top result in yellow
    i,j = np.unravel_index(accumulator.argmax(), accumulator.shape)
    plt.scatter([j], [i], marker='x', color='y')

    d,f = os.path.split(query)[0], os.path.splitext(os.path.split(query)[1])[0]
    plt.savefig(os.path.join(d, f + '_output.png'))

    return

    Uses a GH closure to detect shapes in an image and create nice output
    
Uses a GH closure to detect shapes in an image and create nice output
Uses a GH closure to detect shapes in an image and create nice output
def general_hough(gh, reference_image, query):
    query_image = imread(query, flatten=True)
    query_image = imresize(query_image, 0.25)
    accumulator = gh(query_image)
    plt.clf()
    plt.gray()
    fig = plt.figure()
    fig.add_subplot(2,2,1)
    plt.title('Reference image')
    plt.imshow(reference_image)
    fig.add_subplot(2,2,2)
    plt.title('Query image')
    plt.imshow(query_image)
    fig.add_subplot(2,2,3)
    plt.title('Accumulator')
    plt.imshow(accumulator)
    fig.add_subplot(2,2,4)
    plt.title('Detection')
    plt.imshow(query_image)
    m = n_max(accumulator, 5)
    y_points = [pt[1][0] for pt in m]
    x_points = [pt[1][1] for pt in m]
    plt.scatter(x_points, y_points, marker='o', color='r')
    i,j = np.unravel_index(accumulator.argmax(), accumulator.shape)
    plt.scatter([j], [i], marker='x', color='y')
    d,f = os.path.split(query)[0], os.path.splitext(os.path.split(query)[1])[0]
    plt.savefig(os.path.join(d, f + '_output.png'))
    return
def general_hough ( gh , reference_image , query ) : query_image = imread ( query , flatten = True ) query_image = imresize ( query_image , 0.25 ) accumulator = gh ( query_image ) plt . clf ( ) plt . gray ( ) fig = plt . figure ( ) fig . add_subplot ( 2 , 2 , 1 ) plt . title ( 'Reference image' ) plt . imshow ( reference_image ) fig . add_subplot ( 2 , 2 , 2 ) plt . title ( 'Query image' ) plt . imshow ( query_image ) fig . add_subplot ( 2 , 2 , 3 ) plt . title ( 'Accumulator' ) plt . imshow ( accumulator ) fig . add_subplot ( 2 , 2 , 4 ) plt . title ( 'Detection' ) plt . imshow ( query_image ) m = n_max ( accumulator , 5 ) y_points = [ pt [ 1 ] [ 0 ] for pt in m ] x_points = [ pt [ 1 ] [ 1 ] for pt in m ] plt . scatter ( x_points , y_points , marker = 'o' , color = 'r' ) i , j = np . unravel_index ( accumulator . argmax ( ) , accumulator . shape ) plt . scatter ( [ j ] , [ i ] , marker = 'x' , color = 'y' ) d , f = os . path . split ( query ) [ 0 ] , os . path . splitext ( os . path . split ( query ) [ 1 ] ) [ 0 ] plt . savefig ( os . path . join ( d , f + '_output.png' ) ) return
Uses a GH closure to detect shapes in an image and create nice output
Uses a GH closure to detect shapes in an image and create nice output
'''
    Uses a GH closure to detect shapes in an image and create nice output
    ''' # top 5 results in red # top result in yellow
gh
reference_image
query