Exemplo n.º 1
0
def find_similar(imagenames, plot_features=False):
    '''Find similar images pairs
    '''
    first_figure = True
    images = [ MyImage(i) for i in imagenames ]
    matches = defaultdict(list)
    length = len(images)

    if plot_features:
        for image in images:
            if first_figure:
                first_figure = False
            else:
                pylab.figure()
            sift.plot_features(image.im, image.locs, circle=True)

    for i in range(length):
        this = images[i]
        print 'Find match for', this.filename, ' ',
        for j in range(i+1, length):
            that = images[j]
            sys.stdout.write('.')
            sys.stdout.flush()
            
            matched_points = nn.match_twosided(this.desc, that.desc)
            similarity = sum(matched_points > 0)

            matches[i].append((similarity, j, matched_points))
            matches[j].append((similarity, i, matched_points))
        print ' ',

        # at least 10 points matched
        # and only need top 3 matches
        scores = sorted([k for k in matches[i]
                         if k[0] > 10 ], reverse=True)[:3]
        if not scores:
            print 'No match :('
        else:
            for sim, k, matched_points in scores:
                that = images[k]
                print '%s(%d) ' % (that.filename, sim),

                if first_figure:
                    first_figure = False
                else:
                    pylab.figure()

                if k < i: # only cal the top right triangle
                    this = images[k]
                    that = images[i]
                sift.plot_matches(this.im, that.im,
                                  this.locs, that.locs,
                                  matched_points)
            print

    pylab.show()
Exemplo n.º 2
0
def find_similar(imagenames, plot_features=False):
    '''Find similar images pairs
    '''
    first_figure = True
    images = [MyImage(i) for i in imagenames]
    matches = defaultdict(list)
    length = len(images)

    if plot_features:
        for image in images:
            if first_figure:
                first_figure = False
            else:
                pylab.figure()
            sift.plot_features(image.im, image.locs, circle=True)

    for i in range(length):
        this = images[i]
        print 'Find match for', this.filename, ' ',
        for j in range(i + 1, length):
            that = images[j]
            sys.stdout.write('.')
            sys.stdout.flush()

            matched_points = nn.match_twosided(this.desc, that.desc)
            similarity = sum(matched_points > 0)

            matches[i].append((similarity, j, matched_points))
            matches[j].append((similarity, i, matched_points))
        print ' ',

        # at least 10 points matched
        # and only need top 3 matches
        scores = sorted([k for k in matches[i] if k[0] > 10], reverse=True)[:3]
        if not scores:
            print 'No match :('
        else:
            for sim, k, matched_points in scores:
                that = images[k]
                print '%s(%d) ' % (that.filename, sim),

                if first_figure:
                    first_figure = False
                else:
                    pylab.figure()

                if k < i:  # only cal the top right triangle
                    this = images[k]
                    that = images[i]
                sift.plot_matches(this.im, that.im, this.locs, that.locs,
                                  matched_points)
            print

    pylab.show()
Exemplo n.º 3
0
def plot_match(imagename1, imagename2, show=True, plot_features=True):
    '''Generate SIFT features for two images, plot their
    features onto the original images and link two-sided
    matching points with lines
    '''
    pylab.gray()

    # plot features on images
    # plot matching points
    # matchscores = sift.match_twosided(desc1, desc2)
    matchscores = nn.match_twosided(desc1, desc2)
    sift.plot_matches(im1, im2, locs1, locs2, matchscores)
    pylab.figure()

    if show:
        pylab.show()
Exemplo n.º 4
0
def plot_match(imagename1, imagename2, show=True, plot_features=True):
    '''Generate SIFT features for two images, plot their
    features onto the original images and link two-sided
    matching points with lines
    '''
    pylab.gray()

    # plot features on images
    # plot matching points
    # matchscores = sift.match_twosided(desc1, desc2)
    matchscores = nn.match_twosided(desc1, desc2)
    sift.plot_matches(im1, im2, locs1, locs2, matchscores)
    pylab.figure()

    if show:
        pylab.show()