~bertrand-nouvel/pycvf-keypoints/trunk

« back to all changes in this revision

Viewing changes to lib/gb/find_interest_points.py

  • Committer: tranx
  • Date: 2010-10-01 16:56:14 UTC
  • Revision ID: tranx@havane-20101001165614-u938mdd1y1fgd0o5
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
"""
 
3
% Demo code for matching roughly based on the procedure
 
4
% described in:
 
5
%
 
6
% "Shape Matching and Object Recognition using Low Distortion Correspondence"
 
7
% A. C. Berg, T. L. Berg, J. Malik
 
8
% CVPR 2005
 
9
%
 
10
% code Copyright 2005 Alex Berg
 
11
%
 
12
% questions -> Alex Berg aberg@cs.berkeley.edu
 
13
"""
 
14
import numpy
 
15
import random
 
16
 
 
17
def find_interest_points( signal, desired, r ):
 
18
 
 
19
  """
 
20
  % function [ci,cj] = find_interest_points( signal, desired, r )
 
21
  %
 
22
  % use rejection sampling to find interest points along edges
 
23
  %
 
24
  """
 
25
  rs = r**2;
 
26
  ci = [];
 
27
  cj = [];
 
28
  
 
29
  center_signal = 0;
 
30
  thresh = 0.1*signal.max(); # % initial threshhold
 
31
  tcount = 1;
 
32
  
 
33
  center_signal = signal>=thresh
 
34
  while center_signal.sum()<(desired*2):
 
35
    center_signal = signal>=thresh
 
36
    thresh = thresh*0.9;
 
37
    tcount = tcount+1;
 
38
    if (tcount>10):
 
39
      break
 
40
  
 
41
 
 
42
  # now we have at least 400 points in center_signal
 
43
  # do rejection sampling to geta spatially uniform sample
 
44
  #  keyboard
 
45
  
 
46
  rows,cols = signal.shape[:2]
 
47
  
 
48
  c=numpy.nonzero(center_signal)
 
49
  c=numpy.array(c).T
 
50
  n = c.shape[0]
 
51
  rp = range(n)
 
52
  random.shuffle(rp)
 
53
  
 
54
  c=c[rp]
 
55
  good = numpy.ones((n,))
 
56
  vgood = numpy.zeros((n,))
 
57
  for i in range(n):
 
58
    if (good[i]):
 
59
      notclose = (((c[:,0]-c[i,0])**2) + ((c[:,1]-c[i,1])**2))>=rs
 
60
      good = good*notclose
 
61
      vgood[i] = 1;
 
62
      good[i] = 1;
 
63
      if (numpy.sum(vgood)>=desired):
 
64
        break
 
65
 
 
66
  #print vgood.sum(),desired
 
67
  c = c[vgood>0]
 
68
  #print c.shape
 
69
  #print c
 
70
  return c[:,0],c[:,1]