Ejemplo n.º 1
0
def matches(im1, im2, matches, dist=None, options={}):
    """ show a figure with lines joining the accepted matches in im1 and im2
        input: im1,im2 (images as arrays), locs1,locs2 (location of features),
        matchscores (as output from 'match').
    """

    scale = options.get("scale", 1)
    filename = options.get("filename", None)
    max_dist = options.get("max_dist", 100)
    line_width = options.get("line_width", 0.8)
    size = options.get("size", (12, 8))
    separation = options.get("separation", 20)

    if scale != 1:
        s = numpy.array([scale, scale])
        im1_size = numpy.array(im1.shape[1::-1] * s, dtype=numpy.uint16)
        im2_size = numpy.array(im2.shape[1::-1] * s, dtype=numpy.uint16)
        if scale < 0.5:
            im1_scaled = imaging.get_thumbnail(im1, size=im1_size)
            im2_scaled = imaging.get_thumbnail(im2, size=im2_size)
        else:
            im1_scaled = imaging.open_img(im1, size=im1_size)
            im2_scaled = imaging.open_img(im2, size=im2_size)
        im3 = append_images(im1_scaled, im2_scaled, separation)
        matches = [(m[0] * s, m[1] * s) for m in matches]
    else:
        im3 = append_images(im1, im2, separation)
        im1_scaled = im1

    # Create figure
    fig = pylab.figure(frameon=False, figsize=size)
    ax = pylab.Axes(fig, [0., 0., 1., 1.])

    ax.set_axis_off()
    fig.add_axes(ax)

    # Display image
    ax.imshow(im3)

    # Get colors
    if dist != None and len(dist) == len(matches):
        cs = [
            getRedGreen(numpy.log(d + 1) / numpy.log(max_dist)) for d in dist
        ]
    else:
        cs = ['#00aaff' for m in matches]

    # Plot all lines
    offset_x = im1_scaled.shape[1]
    for i, ((x1, y1), (x2, y2)) in enumerate(matches):
        ax.plot([x1, x2 + offset_x + separation], [y1, y2],
                color=cs[i],
                lw=line_width)

    pylab.xlim(0, im3.shape[1])
    pylab.ylim(im3.shape[0], 0)

    if filename != None:
        fig.savefig(filename, bbox_inches='tight', dpi=72)
Ejemplo n.º 2
0
def matches(im1, im2, matches, dist = None, options = {}) :
    """ show a figure with lines joining the accepted matches in im1 and im2
        input: im1,im2 (images as arrays), locs1,locs2 (location of features),
        matchscores (as output from 'match').
    """

    scale    = options.get("scale", 1)
    filename   = options.get("filename", None)
    max_dist   = options.get("max_dist", 100)
    line_width = options.get("line_width", 0.8)
    size       = options.get("size", (12, 8))
    separation = options.get("separation", 20)

    if scale != 1 :
        s = numpy.array([scale, scale])
        im1_size = numpy.array(im1.shape[1::-1] * s, dtype=numpy.uint16)
        im2_size = numpy.array(im2.shape[1::-1] * s, dtype=numpy.uint16)
        if scale < 0.5 :
            im1_scaled = imaging.get_thumbnail(im1, size = im1_size)
            im2_scaled = imaging.get_thumbnail(im2, size = im2_size)
        else :
            im1_scaled = imaging.open_img(im1, size = im1_size)
            im2_scaled = imaging.open_img(im2, size = im2_size)
        im3 = append_images(im1_scaled, im2_scaled, separation)
        matches = [(m[0] * s, m[1] * s) for m in matches]
    else :
        im3 = append_images(im1,im2, separation)
        im1_scaled = im1

    # Create figure
    fig = pylab.figure(frameon=False, figsize=size)
    ax = pylab.Axes(fig, [0., 0., 1., 1.])

    ax.set_axis_off()
    fig.add_axes(ax)

    # Display image
    ax.imshow(im3)

    # Get colors
    if dist != None and len(dist) == len(matches) :
        cs = [getRedGreen(numpy.log(d+1)/numpy.log(max_dist)) for d in dist]
    else :
        cs = ['#00aaff' for m in matches]

    # Plot all lines
    offset_x = im1_scaled.shape[1]
    for i,((x1,y1),(x2,y2)) in enumerate(matches) :
        ax.plot([x1, x2+offset_x + separation], [y1,y2], color=cs[i], lw=line_width)

    pylab.xlim(0,im3.shape[1])
    pylab.ylim(im3.shape[0],0)

    if filename != None :
        fig.savefig(filename, bbox_inches='tight', dpi=72)
Ejemplo n.º 3
0
 def create_image(self, path, max_size, metric):
     """ Match an image with itself finding the closest neighbors within that image """
     # Open image
     img_data = imaging.open_img(path, max_size)
     # Get descriptors
     keypoints, descriptors = matchutil.get_features(img_data)
     # Match
     matches = matchutil.flann_match(descriptors, descriptors, k=2)
     # Distances and positions
     distances = numpy.array([r[1].distance for r in matches])
     positions = numpy.array([k.pt for k in keypoints])
     # build position_tree
     position_tree = BallTree(positions, metric=metric)
     # Collect data
     self.original = {
         "descriptors": descriptors,
         "positions": positions,
         "distances": distances,
         "position_tree": position_tree,
         "size": img_data.shape
     }
Ejemplo n.º 4
0
 def create_image(self, path, max_size, metric) :
     """ Match an image with itself finding the closest neighbors within that image """
     # Open image
     img_data = imaging.open_img(path, max_size)
     # Get descriptors
     keypoints, descriptors = matchutil.get_features(img_data)
     # Match
     matches = matchutil.flann_match(descriptors, descriptors, k=2)
     # Distances and positions
     distances = numpy.array([r[1].distance for r in matches])
     positions = numpy.array([k.pt for k in keypoints])
     # build position_tree
     position_tree = BallTree(positions, metric = metric)
     # Collect data
     self.original = {
         "descriptors" : descriptors,
         "positions" : positions,
         "distances" : distances,
         "position_tree" : position_tree,
         "size" : img_data.shape
     }
Ejemplo n.º 5
0
 def get_match_fun(i) :
     # Collect matches
     paths = get_path(i)
     query_path, target_path = paths["A"], paths["C"]
     query_cache, target_img = Metric_Cache(query_path), imaging.open_img(target_path)
     return match_fun(query_cache, target_img, options = options)