~bertrand-nouvel/pycvf-keypoints/trunk

« back to all changes in this revision

Viewing changes to lib/gb/normalize_descriptors.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
 
 
15
import numpy
 
16
 
 
17
from compute_sample_points import compute_sample_points
 
18
 
 
19
def normalize_descriptors(features,rs,nthetas):
 
20
  """
 
21
  % function features = normalize_descriptors(features,rs,nthetas);
 
22
  %
 
23
  % normlize the gb descriptors... this can be done based on sample
 
24
  % variation using a population of gb descriptors, but here we 
 
25
  % simply normalize each sample by the sqrt of the radius
 
26
  """
 
27
 
 
28
  sample_points,sample_points_r,sample_points_rb  = compute_sample_points(rs,nthetas)
 
29
  nm = 1./(numpy.sqrt(sample_points_r)+(sample_points_r==0))
 
30
 
 
31
  for fi in range(len(features)):
 
32
    ## take sample points
 
33
    features[fi] = features[fi]/nm.reshape(-1,1).repeat(features[fi].shape[1],axis=1)
 
34
    
 
35
  nm = (numpy.dstack(features)**2).sum(axis=2).sum(axis=1)**.5
 
36
  nm[nm<0.001]=1 #?(0?) -> avoid division by zero
 
37
  for fi in range(len(features)):
 
38
    features[fi] = features[fi]/nm.reshape(-1,1).repeat(features[fi].shape[1],axis=1)
 
39
    
 
40
  return features 
 
41
 
 
42
 
 
43
 
 
44