from pylab import * from PIL import Image from PCV.localdescriptors import harris from numpy import * im = asarray(Image.open('1.jpeg').convert('L')) harrisim = harris.compute_harris_response(im) harrisim1 = 255 - harrisim figure() gray() subplot(141) imshow(harrisim1) threshold = [0.01, 0.05, 0.1] for i, thres in enumerate(threshold): filtered_coords = harris.get_harris_points(harrisim, 10, thres) subplot(1, 4, i + 2) imshow(im) plot([p[1] for p in filtered_coords], [p[0] for p in filtered_coords], '*') axis('off') show()
from PCV.localdescriptors import harris from PCV.tools.imtools import imresize """ This is the Harris point matching example in Figure 2-2. """ im1 = array(Image.open("../data/crans_1_small.jpg").convert("L")) im2 = array(Image.open("../data/crans_2_small.jpg").convert("L")) # resize to make matching faster im1 = imresize(im1,(im1.shape[1]/2,im1.shape[0]/2)) im2 = imresize(im2,(im2.shape[1]/2,im2.shape[0]/2)) wid = 5 harrisim = harris.compute_harris_response(im1,5) filtered_coords1 = harris.get_harris_points(harrisim,wid+1) d1 = harris.get_descriptors(im1,filtered_coords1,wid) harrisim = harris.compute_harris_response(im2,5) filtered_coords2 = harris.get_harris_points(harrisim,wid+1) d2 = harris.get_descriptors(im2,filtered_coords2,wid) print 'starting matching' matches = harris.match_twosided(d1,d2) figure() gray() harris.plot_matches(im1,im2,filtered_coords1,filtered_coords2,matches) show()
from pylab import * from numpy import * from PIL import Image from PCV.localdescriptors import harris """ Example of detecting Harris corner points (Figure 2-1 in the book). """ # open image im = array(Image.open('../data/empire.jpg').convert('L')) # detect corners and plot harrisim = harris.compute_harris_response(im) filtered_coords = harris.get_harris_points(harrisim, 10, threshold=0.01) harris.plot_harris_points(im, filtered_coords) # plot only 200 strongest harris.plot_harris_points(im, filtered_coords[:200])
from PIL import Image from PCV.localdescriptors import harris from PCV.tools.imtools import imresize """ This is the Harris point matching example in Figure 2-2. """ im1 = array(Image.open("data/crans_1_small.jpg").convert("L")) im2 = array(Image.open("data/crans_2_small.jpg").convert("L")) # resize to make matching faster im1 = imresize(im1, (im1.shape[1] / 2, im1.shape[0] / 2)) im2 = imresize(im2, (im2.shape[1] / 2, im2.shape[0] / 2)) wid = 5 harrisim = harris.compute_harris_response(im1, 5) filtered_coords1 = harris.get_harris_points(harrisim, wid + 1) d1 = harris.get_descriptors(im1, filtered_coords1, wid) harrisim = harris.compute_harris_response(im2, 5) filtered_coords2 = harris.get_harris_points(harrisim, wid + 1) d2 = harris.get_descriptors(im2, filtered_coords2, wid) print 'starting matching' matches = harris.match_twosided(d1, d2) figure() gray() harris.plot_matches(im1, im2, filtered_coords1, filtered_coords2, matches) show()