1
# -*- coding: utf-8 -*-
3
% Demo code for matching roughly based on the procedure
6
% "Shape Matching and Object Recognition using Low Distortion Correspondence"
7
% A. C. Berg, T. L. Berg, J. Malik
10
% code Copyright 2005 Alex Berg
12
% questions -> Alex Berg aberg@cs.berkeley.edu
17
from numpy.fft import fft,ifft
20
from pycvfext.image.lib import rescale
22
def imresize(img,sz,meth):
23
#return rescale.Rescaler2d(sz).process(img)
24
return scipy.misc.pilutil.imresize(img,sz)#,meth)
26
def imrotate(img,ang,meth1,meth2):
27
return scipy.misc.pilutil.imrotate(img,ang,meth1)
30
from pycvfext.image.nodes.hilbert import hilbert
33
def make_fb( nori=4, aspect=3, scale=4, half_support=15):
34
support = 2*half_support + 1;
36
FB = numpy.zeros((nori,support,support))
39
X,Y = numpy.mgrid[0:(10*support+1),0:(10*support+1)]
41
X = X - X.mean(axis=-1)
42
Y = Y - Y.mean(axis=-1)
45
R = numpy.sqrt(X**2 + (aspect*Y)**2); ## compute distance to center adding aspect scaling in direction Y
46
### variance = 10*scale
47
### compute gaussian PDF
48
G = (1/(10*sigma*numpy.sqrt(2*pi)))*numpy.exp(-(R**2)/(2*100*sigma**2));
52
dx,dy=scipy.gradient(G);
56
## introduce the imaginary part of the hilber transform s even signal
57
a_Even = numpy.imag(hilbert(a_Odd))
61
a_Even = a_Even - a_Even.mean()
62
a_Even = a_Even / abs(a_Even).sum()
63
a_Odd = a_Odd - a_Odd.mean()
64
a_Odd = a_Odd / abs(a_Odd).sum()
68
a_Odd = imresize(a_Odd,[support,support],'bilinear')
69
a_Even = imresize(a_Even,[support,support],'bilinear')
72
## now generate in all orientations
74
oris=numpy.zeros((nori,))
76
for i in range(nori//2):
81
F = imrotate(a_Odd,theta,'bilinear','crop')
87
F = imrotate(a_Even,theta,'bilinear','crop');
b'\\ No newline at end of file'